1
General Discussion / Running demos in Flex project from mxml
« on: August 12, 2011, 06:37:23 pm »
Hello,
I don't know if you guys have any examples of doing this but I'm attempting to port over some of the demo code to be used in a Main.mxml file. There is however some difficulty in doing this and keeping your demos intact. For one I'm attempting to execute the code like such...
protected function application1_applicationCompleteHandler(event:FlexEvent):void
{
var obj:PrimitiveTest = new PrimitiveTest();
container.addChild(obj);
}
//container being a....
<s:SpriteVisualElement id="container" width="{this.width}" height="{this.height}"/>
The problem is that you can not actually get a reference to the stage from a class file until after it is actually added to the stage making it a UIObject at that point. I have added a listener to wait for this in the baseTest class like such...
public function BaseTest()
{
// Since you have to have a reference to the stage first we must wait until this class has been added to the stage.
addEventListener(Event.ADDED_TO_STAGE, stageAddHandler);
}
private function stageAddHandler(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, stageAddHandler);
Yogurt3D.instance.addEventListener( Yogurt3DEvent.READY, onContext3DReady );
Yogurt3D.instance.init(stage);
........
}
The rest of the code follows from the example you have created. However, I think there is something getting out of wack here with the order of events. When I run this demo I get no errors and everything seems to compile fine and then it freezes up almost locking the browser. So if you guys have any ideas please let me know otherwise I will post a solution here as soon as I find one.
I think that running the Flex application using mxml files has obvious benefits as you can integrate it much easier into other development workflow and manipulate the layout a bit easier.
-Thanks!
I don't know if you guys have any examples of doing this but I'm attempting to port over some of the demo code to be used in a Main.mxml file. There is however some difficulty in doing this and keeping your demos intact. For one I'm attempting to execute the code like such...
protected function application1_applicationCompleteHandler(event:FlexEvent):void
{
var obj:PrimitiveTest = new PrimitiveTest();
container.addChild(obj);
}
//container being a....
<s:SpriteVisualElement id="container" width="{this.width}" height="{this.height}"/>
The problem is that you can not actually get a reference to the stage from a class file until after it is actually added to the stage making it a UIObject at that point. I have added a listener to wait for this in the baseTest class like such...
public function BaseTest()
{
// Since you have to have a reference to the stage first we must wait until this class has been added to the stage.
addEventListener(Event.ADDED_TO_STAGE, stageAddHandler);
}
private function stageAddHandler(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, stageAddHandler);
Yogurt3D.instance.addEventListener( Yogurt3DEvent.READY, onContext3DReady );
Yogurt3D.instance.init(stage);
........
}
The rest of the code follows from the example you have created. However, I think there is something getting out of wack here with the order of events. When I run this demo I get no errors and everything seems to compile fine and then it freezes up almost locking the browser. So if you guys have any ideas please let me know otherwise I will post a solution here as soon as I find one.
I think that running the Flex application using mxml files has obvious benefits as you can integrate it much easier into other development workflow and manipulate the layout a bit easier.
-Thanks!