Nate Beck has posted a great explaination about how Flash player security works. He covers what types of sand boxes there are, and for what they are good for.
Check it out at his blog: Understanding Local Flash Player Security!
Archive for the ‘PushButton Engine’ category
Understanding Local Flash Player Security
March 7th, 2010PBE Series: using SchemaGenerator
January 22nd, 2010Previously, in PBE Series: dynamically get list of public members, properties and methods of object or class, I noted that
SchemaGenerator.instance.generateSchema();
“dumps all classes and public info to a xml file”.
We’ll, I’ve used it now, and I must admit that was a lie ![]()
So here’s how you use it, and what it results in!
First, you need to establish a local connection, and then call generateSchema:
conn = new LocalConnection(); conn.client = this; conn.allowDomain('*'); try { conn.connect("_SchemaConnection"); } catch (error:ArgumentError) { trace("Can't connect to _SchemaConnection"); } SchemaGenerator.instance.generateSchema();
SchemaGenerator.instance.generateSchema will then call OnSchemaReceived in your class, so you need to add that. It takes two string arguments: type and data. Type is either “START”, “END”, “ERROR” or “TYPE”. Data is an XML description of the current processed class (internally it uses flash.utils.describeType), which you then can further interact with.
Here’s an example of how OnSchemaReceived could look like:
public function OnSchemaReceived(type:String, data:String):void { switch( type ) { case "START": break; case "END": break; case "ERROR": break; case "TYPE": { var myXML:XML = new XML(data); myXML.ignoreWhite = true; var xmlList:XMLList = myXML.child("factory"); //Check accessors: for each (var acc:XML in xmlList.accessor) { //DO SOMETHING. } //Check public variables: for each (var pVar:XML in xmlList.variable) { //DO SOMETHING. } } break; } }
That should help you getting started!
Level Master 2000 goes Qt
January 9th, 2010New year, new news – and this time everything is different! I’ve been through some interesting discussions with Ben Garney (one of the big guys behind PushButton Engine) regarding how to tackle a general purpose editor beast for PushButton Engine. We came to the conclusion, that we’d rather try a non flash/flex way for the UI (mainly due to possible performance problems).
One solution would have been .NET/Mono, but that didn’t convince us at a first glance. Our second approach is using Qt!
Since Flash can’t comminicate directly with Cpp/Qt, we need to do the following:
- In Flash, we use ExternalInterface to communicate with the outside world (meaning Javascript)
- In Qt, we run a Webview, which loads the SWF and catches the ExternalInterface calls.
- These caught calls are then passed on to Qt
So in short, it’s like: Flash >> Javascript >> Qt and the otherway.
We’ll see how this decision turns out in the end, but it’s an interesting approach indeed (and in case of emergency, there are ways to improve performance)!
For now, I can say, that I got the basic communication working:

It features:
- Entity selection
- Display the as “editable” marked properties of the selected entity, grouped by components
- (W.I.P.)Modify the properties: numbers and strings working, custom data types (like a point) on the way
Next upcoming features:
- Entity Browser: visualisation
- Entity Browser: interaction (selecting entities, adding + deleting components)
Stay tuned!
Posted in Level Master 2000, PushButton Engine
PBE Series: clickable component
January 2nd, 2010Prerequisites:
- Use a current version of PushButton Engine.
- A properly initialized scene (see PBE Series: initializing your scene via ActionScript on how to setup it up)
Today I will show you, how to create a component for PushButton Engine, that registers, if an entity got clicked on or not.
In general, you got two possibilities how to handle this:
- per object level
- on a global level
Per object level: since it’s flash, you can simply add an event listener to your graphics component, which listens to click events.
I personally don’t like that too much though, so let’s consider variant two: global level.
It’s a component which exists once in the scene, and not per entity. It listens to click events which happen on the main stage, and on each click, it uses the built in functions PBE.scene.getRenderersUnderPoint and/or PBE.spatialManager.getObjectsUnderPoint to determine, which objects got clicked on.
This version only uses the getRenderersUnderPoint, the main stuff is going on in the OnClick method:
package { import com.pblabs.engine.PBE; import com.pblabs.engine.debug.Logger; import com.pblabs.engine.entity.EntityComponent; import com.pblabs.rendering2D.DisplayObjectRenderer; import flash.events.MouseEvent; import flash.geom.Point; public class ClickComponent extends EntityComponent { protected override function onAdd():void { PBE.mainStage.addEventListener(MouseEvent.CLICK, OnClick ); } private function OnClick(e:MouseEvent):void { var results:Array = new Array(); var point:Point = new Point( PBE.mainStage.mouseX, PBE.mainStage.mouseY ); var foundRenderers:Boolean = PBE.scene.getRenderersUnderPoint( point, results ); for each( var obj:DisplayObjectRenderer in results ) { Logger.print( this, obj.name ); } } protected override function onRemove():void { PBE.mainStage.removeEventListener(MouseEvent.CLICK, OnClick ); } } }
Now if you want to get the spatial objects, simply use this:
var spatials:Array = new Array(); PBE.spatialManager.getObjectsUnderPoint( PBE.scene.transformScreenToWorld(point), spatials, new ObjectType("Renderable")); for each( var spatialObj:ISpatialObject2D in spatials ) { Logger.print( this, spatialObj.position.toString() ); }
The main difference is that getRenderersUnderPoint results in DisplayObjectRenderers, and getObjectsUnderPoint results in ISpatialObject2Ds.
Also, see that you can supply an object mask. Leaving it null will take all objects into consideration.
All in all you can see, how easy this is (for such a complex sounding task)!
Posted in Level Master 2000, PushButton Engine, Tutorials
PBE Series: dynamically get list of public members, properties and methods of object or class
December 27th, 2009Now this isn’t necessarily only related to PushButton Engine. Without using the Logger functions, it would also work with “plain” ActionScript. So what do I want to do here? My main problem was, with Level Master 2000, I want to have UI-based component composition. And each component has different properties which should be settable in the editor. And it looks like this is pretty easy to do with ActionScript. All you need to do is get an XML description of your object or class, by using the built in function describeType:
//Produces an XML object that describes the ActionScript //object named as the parameter of the method: var varList:XML = flash.utils.describeType( /*INSERT OBJECT OR CLASS*/ );
And then, depending on what you want to access (properties, members or functions), just iterate over your XML and you’re good!
Logger.print(this, "Properties:"); for each (var a:XML in varList.accessor) { Logger.print(this, a.@name+" : "+a.@type); }
Logger.print(this, "Variables:"); for each (var b:XML in varList.variable) { Logger.print(this, b.@name+" : "+b.@type); }
Logger.print(this, "Methods:"); for each (var c:XML in varList.method) { Logger.print(this, c.@name+" : "+c.@type); }
For me with my editor, I’ll probably do this once at startup and keep the information for all the components stored somewhere. I currently don’t know how performance is, but I guess it’s gonna be better that way. If it turns out to be a wrong approach, I’ll post my conclusion here
Edit – doing it the PushButton way:
Of course there seems to be a much easier way doing it with PushButton Engine. I must admit, I haven’t tried it, but it seems there’s this built in function which sort of dumps all classes and public info to a xml file by just using:
SchemaGenerator.instance.generateSchema();
Nice!
Posted in Level Master 2000, PushButton Engine, Tutorials