View Full Version : run function everytime a component is viewd / selected

10-19-2006, 11:14 AM
hi - can anyone tell me how to run a function within a component evey time the component is selected / viewed - (not created)

i.e. I dont want the function to run in the creationComplete handler as it is needed to be ran as soon as (and everytime) the component is selected / viewed - whi may be multiple times during the runtime of the application etc....

is there some sort of event I can use....?

sorry I am reasonably new to flex, so my terminology and descriptions may be a bit off when trying to explain myself….. so I will appologise in advance, but give it a go anyway...

My main MXML Application file contains an ApplicationControlBar containing a ViewStack that then links to the other components within my application etc... :

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:mi="components.*" layout="absolute">

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

<mx:ViewStack id="menu_vs">
<mi: page1 id="page_1" label="page1"/>
<mi: page2 id="page_2" label="page2"/>
<mi: page3 id="page_3" label="page3"/>
<mi: page4 id="page_4" label="page4"/>

then when one of the "links" is selected for the 1st time.... if I call a function on the creationComplete event and everything works fine and as it is supposed to.... but after the page has been created the creationComplete event will not run again - for example if I leave the page / component and return to it.......
I need the function to run every time the component is "returned to" whether it has been created or not, because in some cases I send ID's and other variables through DataGrid click events etc....

mmm I hope it makes sense, and it can be understood what I am trying to do / what I am getting at…. ?

Thanks, and sorry for any inconvenience,

10-19-2006, 01:34 PM
Hi Jon. The creationComplete event fires when the component is first instantiated in the application, after which it won't fire (whether or not it is visible).

I guess it depends on what the component is that you're extending, but how about:

private function linkClick(eventObj:Event):void

<mi:page1 id="page_1" label="page1" click="{linkClick(event)}"/>

10-19-2006, 03:37 PM
thats pefect "Flexy" - it works a treat!!!

sorry - I am new to Flex (although enjoying learning it) and I was not aware of (and to be honest dod not even think about) the click property within the viestact link id etc.....


10-19-2006, 04:02 PM
also take a look at the 'focusIn' event.

10-20-2006, 07:43 AM
Hi Tink...

I was aware of the focusIn Event.. but as I am using a ViewStack within my main application I thus have my additional application components contained within vBoxe tags (not the actual Application tag etc..) and when I treid to use the focusIn event it did not seem to be possible for my case (with the application tag)

Do you know if there is another event I can use within vBoxes - or am I wrong and you can use the focusIn within the vBox?