I would recommend using some design patterns or frameworks.  For
example, Cairgorm lets you broadcast special events (Cairngorm events)
which are responded to by a central Cairngorm command class.  This
command class can change the state of the application. 

As for not doing it in MXML because it contains animations, you can
extend the Button class or even better just make a custom button
component (which is also just extending the Button class) and animate
within that component, then in your MXML you can insert the buttons and
change the state by doing:

<myComponents:MyButtonComponent label="Main Menu"
click="myChangeStateMethod()"/>

By nesting buttons deep within actionscript classes you can use event
bubbling to capture the event, but really, there are better less
complicated ways to handle this.

Jason Merrill
Bank of America  
GT&O L&LD Solutions Design & Development 
eTools & Multimedia 

Bank of America Flash Platform Developer Community


Are you a Bank of America associate interested in innovative learning
ideas and technologies? 
Check out our internal  GT&O Innovative Learning Blog & subscribe.




 

>>-----Original Message-----
>>From: [EMAIL PROTECTED] 
>>[mailto:[EMAIL PROTECTED] On Behalf 
>>Of Anthony Cintron
>>Sent: Friday, March 07, 2008 11:24 PM
>>To: Flash Coders List
>>Subject: Re: [Flashcoders] Using States, MXML, Events, O' My
>>
>>The custom class that has the button event is a composite 
>>class inside another class (we'll call that MainInterActive 
>>class). MainInterActive is than instantiated in a main mxml 
>>application inside a state node. I could try what you 
>>mentioned but the composite classes' buttons are not really 
>>available  to the main application. Unless there is a way I 
>>could subscribe to that button, although it is a child of the 
>>child class in MainInterActive.
>>The reason why I'm not creating the buttons using mxml is 
>>because they are doing some funky animations.
>>
>>thanks for your help on this, any ideas for a resolution on 
>>accessing the button or buttons event?
>>
>>Anthony
>>
>>On Fri, Mar 7, 2008 at 9:30 PM, Merrill, Jason < 
>>[EMAIL PROTECTED]> wrote:
>>
>>> If your button in the custom class is broadcasting an 
>>event, say for 
>>> an example, and event called "changed", you can add an 
>>event listener 
>>> in a script tag in the main MXML.  A snippet would be:
>>>
>>>                private function addListeners():void
>>>                {
>>>
>>> myCustomClassInstance.addEventListener("changed", onChanged);
>>>                }
>>>
>>>                private function onChanged():void
>>>                {
>>>                        currentState = "myOtherState";
>>>                }
>>>
>>> However, if you class creates buttons, why not have those buttons 
>>> created with MXML instead of Actionscript?
>>>
>>> There is a great Flex list on Yahoo! called Flexcoders 
>>which would be 
>>> more capable to answer this than this list.
>>>
>>> Jason Merrill
>>> Bank of America
>>> GT&O L&LD Solutions Design & Development eTools & Multimedia
>>>
>>> Bank of America Flash Platform Developer Community
>>>
>>>
>>> Are you a Bank of America associate interested in 
>>innovative learning 
>>> ideas and technologies?
>>> Check out our internal  GT&O Innovative Learning Blog & subscribe.
>>>
>>>
>>>
>>>
>>>
>>>
>>> >>-----Original Message-----
>>> >>From: [EMAIL PROTECTED]
>>> >>[mailto:[EMAIL PROTECTED] On Behalf Of 
>>> >>Anthony Cintron
>>> >>Sent: Friday, March 07, 2008 6:14 PM
>>> >>To: [email protected]
>>> >>Subject: [Flashcoders] Using States, MXML, Events, O' My
>>> >>
>>> >>I have a question about MXML and ActionScript and how they 
>>> >>communicate with each other.  I'm working with the State tage to 
>>> >>change views. I have a Class called SpacePorter; it has 4 buttons 
>>> >>that dispatchEvents( MyButton.BUTTON_CLICKED). Space Porter is 
>>> >>instantiated into my Home Class.
>>> >>Home class is than created using mxml in my root Application.
>>> >>Now, I want to be able with AS3 or MXML to subscribe to that 
>>> >>Broadcast so my State can change, depending on the button 
>>that was 
>>> >>clicked. I can't quite wrap my head around this with my 
>>lack of MXML 
>>> >>and ActionScript relations - especially with the CDATA 
>>tags. I tried 
>>> >>getting the button object through AS, by doing:
>>> >>homeView.button, but it seems as though i can't get to the 
>>> >>properties of an mxml (instantiated object) from a AS 
>>script inside 
>>> >>the script tag.
>>> >>
>>> >>I hope this makes some sense, if need be I can explain some more. 
>>> >>Could really use the help on this. This is great real 
>>world attempt 
>>> >>of me using Flex.
>>> >>
>>> >>Anthony C.
>>> >>
>>> >>--
>>> >>_______________________________________________
>>> >>Flashcoders mailing list
>>> >>[email protected]
>>> >>http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>> >>
>>> _______________________________________________
>>> Flashcoders mailing list
>>> [email protected]
>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>
>>
>>
>>
>>--
>>Anthony Cintron
>>Flash || Flash Developer
>>www.sweetiesandgangsters.com
>>[EMAIL PROTECTED]
>>_______________________________________________
>>Flashcoders mailing list
>>[email protected]
>>http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to