General Category > General Discussion

Running demos in Flex project from mxml

(1/1)

cctman:
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!

lucygreen:
I am very interested in this post!Thans very much. I am wonderring if i can share your article in the post of society,Then more friends can talk about this post .
Share more:Replica Handbag

Gurel Erceis:
The base test is not fit to add the swf directly into a flex project.

The best way is copy the BaseTest constructor code into a init method and call the init from flex. The main problem is that the stage cannot be accessed the same way from flex and actionscript projects.

I'll post an example for building Yogurt3d directly from flex.

Navigation

[0] Message Index

Go to full version