If you feel that it is important to separate MXML and ActionScript, I suggesting writing MXML event attributes like this

 

   <mx:Button id="okButton" label="OK" click="okButton_click(event)"/>

 

and then implementing okButton_click() in a separate .AS file that you bring in using

 

    <mx:Script source="MyApp.script.as"/>

 

That way, the MXML doesn't really do anything; it just makes sure that the appropriate AS event handler gets set up.

 

I can also think of two other ways to solve your problem, but I don't recommend either one.

 

You could set creationPolicy="all" on the ViewStack. But this will defeat the purpose of MXML's "deferred instantiation" feature, which is to minimize startup time by not creating visual components (such as the children of the 2nd pane of an ViewStack) until they need to be displayed.

 

You could also override childrenCreated() in each ViewStack pane and, after calling childrenCreated(), use addEventListener() to attach your event handlers to that pane's children.

 

- Gordon

 


From: [email protected] [mailto:[email protected]] On Behalf Of Sascha Balkau
Sent: Friday, August 18, 2006 6:28 PM
To: [email protected]
Subject: RE: [flexcoders] How to set EventListeners to undrawn components on a ViewStack?

 

Thanks Gordon! Sometimes I don’t see the easiest solution by myself! However I’m trying to keep MXML code and functionality code separate so I’m wondering if there is another workaround for this? Though I can live with your suggestion in this situation.

 

Sascha

 

 

 


From: [EMAIL PROTECTED]ups.com [mailto:[EMAIL PROTECTED]ups.com] On Behalf Of Gordon Smith
Sent: Saturday, 19. August, 2006 08:39
To: [EMAIL PROTECTED]ups.com
Subject: RE: [flexcoders] How to set EventListeners to undrawn components on a ViewStack?

 

Why call addEventListener() yourself? If you simply put an mouseDown or whatever event atttribute on your content item in MXML, it should work fine; addEventListener() will get called for you when the content item gets created.

 

- Gordon

 


From: [EMAIL PROTECTED]ups.com [mailto:[EMAIL PROTECTED]ups.com] On Behalf Of Sascha Balkau
Sent: Friday, August 18, 2006 5:28 AM
To: [EMAIL PROTECTED]ups.com
Subject: [flexcoders] How to set EventListeners to undrawn components on a ViewStack?

 

Hi list,

I'm using a LinkBar with a ViewStack and on any of the ViwStack contents I
have a button that needs to get a MouseEvent listener.

When I start the app, I get an exception ": Cannot access a property or
method of a null object reference." Because all the buttons on the VieStacks
that have not yet been drawn are not defined for the AddEventListener.

Is there an easy workaround for this situation?

Thanks,
Sascha

___

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to