PDA

View Full Version : dispatch event


ljonny18
11-06-2006, 09:21 AM
Hi - can someone help.....

I have a simple query, but am not sure of the best way to go about doing it. I have read up on the events and given them a go, but have had no joy.

Basically, for example, I have a main mxml file "main.mxml" containing a view stack linking to an additional 2 mxml components:

<mx:ApplicationControlBar id="appBar_apc">
<mx:LinkBar dataProvider="viewStack_vs"/>
</mx:ApplicationControlBar>

<mx:ViewStack id="viewStack_vs">
<mi:page1 id="page_1" label="this is page 1"/>
<mi:page2 id="page_2" label="this is page 2"/>
</mx:ViewStack>

I want to have a button in page1.mxml which when is clicked runs a function that is in page2.mxml!
I guess an event can be dispatched that is listened for in page2.mxml and runs the function when it is dispatched etc.... although I can’t work out how to do this :(

page1.mxml:
<mx:button label=”click me” click=”run the testFunction in page2.mxml”/>

page2.mxml
public function testFunction()
{
Alert.show(“hello”);
}

Etc…..

Can anyone help? or post an example for me?

Thanks,
Jon.

CDHBookingEdge
11-06-2006, 11:48 AM
jonny see if this helps you get a better hold on things as far as events: Using Events (http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000461.html)

Also just a thought. you might be able to simply call that method directly using something like the following:
ParentDocument.viewStack_vs[2].testFunction();
you might need to do a bit of casting on it to get it to work though.

Christopher