flash - DisplayObjectContainer into Flex component... how? -


i'll re-write question clearer.

i'm trying class file flash builder.

everything in class sits inside sprite called maincontainer. i'm trying `maincontainer' hold graphics class flex application.

this proving problem many various ways of doing (it seems going numerous google searches).

first off declare mxml canvas image inside (as read work):

<mx:canvas x="268" y="10" width="756" height="680" id="canvas">     <mx:image id="spritelayer" x="268" y="0" width="756" height="700" scalecontent="false" autoload="true">      </mx:image> </mx:canvas>} 

ok, plan pass image reference of spritelayer class i'm trying run:

             import includes.spirograph;             public var spiro:spirograph = new spirograph(spritelayer); 

unfortunately ever passes null spirograph class:

         function spirograph(canvasimage:image):void         {                this.canvas = canvasimage;             maincontainer.graphics.beginfill(0xffffff);             maincontainer.graphics.drawrect(290, 0, 670, 700);             maincontainer.graphics.endfill();              ui.addchild(maincontainer);             canvas.addchild(ui); }

not sure do.

many thanks.

i think need read on flex component lifecycle. spritelayer component not yet created or initialized when new spirograph(spritelayer) code called. when code called?

the flex component lifecycle series of methods , events create flex ui. can override these methods, or listen these events 'do stuff'. canvas , spritelayer not created until after createchildren method called; , default property values defined before happens.

you override createchildren() , initialization there:

override protected function createchildren():void{  super.createchildren()  spiro  = new spirograph(spritelayer); } 

or listen initialize event , set default in there:

<mx:myparentcomponent initialize="oninitialize()">  <fx:script>    protected function oninitialize():void{     spiro  = new spirograph(spritelayer);   }  </fx:script> </mx:myparentcomponent> 

as poster commented, initialization (like above) in creationcomplete event, although recommend against doing that. creationcomplete event dispatches @ end of lifecycle; , changes you're doing cause renderer event "restart", forcing of lifecycle parse through again; component resized (measure()) , elements repositioned (updatedisplaylist()). setting default values in lifecycle possible recommended.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -