Has anyone tried using Box2D from mxml? Is this possible or feasible? I'd like to design a more conventional UI around a Box2D simulation, but most mxml samples I've seen make embedding sprites/movieclips somewhat difficult.
Box2D from MXML
FlashYes, it is possible to use box2d with flex. Month ago I've made the simulation with flex components as physical objects. Just use tag <mx:Script> in your mxml-file.
If you want to use external graphics content, you have to use meta-tag [Embed] for embed graphic stuff in swf or URLLoader class for loading content runtime.
If you want to use external graphics content, you have to use meta-tag [Embed] for embed graphic stuff in swf or URLLoader class for loading content runtime.
Wow, that simulation's quite impressive. I know about the <mx:Script>, but how are you creating the canvas? Below is what I tried. I basically just took my simulation class, called Main, and appended it to the application tag. While it compiles just fine, it doesn't draw anything. If I compile my Main.as file by itself, the simulation runs just fine. Is there something else the <mx:Application> tag requires, or doesn't allow?
<mx:Application paddingBottom="0" paddingTop="0" paddingLeft="0" paddingRight="0" layout="vertical" pageTitle="The Last Line" creationComplete="init()">
<mx:Script>
import Main
private function init():void
{
var myMain:Main = new Main();
this.rawChildren.addChild(myMain);
}
</mx:Script>
</mx:Application>
<mx:Application paddingBottom="0" paddingTop="0" paddingLeft="0" paddingRight="0" layout="vertical" pageTitle="The Last Line" creationComplete="init()">
<mx:Script>
import Main
private function init():void
{
var myMain:Main = new Main();
this.rawChildren.addChild(myMain);
}
</mx:Script>
</mx:Application>
Another note, my Main class just inherits MovieClip, the same way Erin's TestBed example does.
Original thread: https://box2d.org/forum/viewtopic.php?t=400