When you search to accomplish a task in Flex and can’t do it, then look for it in JavaScript because many of things that are not possible in Flex are possible using JavaScript which is the backbone of your Flex App.
I had a requirement were i wanted to refresh/reload the Flex App ,but i couldn’t do it in Flex and finally i realized that it may be possible using JavaScript then i went for it and coded, “WOW” i said to my self because it worked ,my App got reloaded/refreshed.
Then decided to post it in Blog, because it may help out other Flex lovers.
Code Example:
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute”>
<mx:Button x=”83″ y=”196″ label=”Button” click=”reloadpage(event)”/>
<mx:Script>
<![CDATA[
private function reloadpage(event:MouseEvent):void
{
var ref:URLRequest = new URLRequest("javascript:location.reload(true)");
navigateToURL(ref, "_self");
}
]]>
</mx:Script>
</mx:Application>
Here on click of Button the App is reloaded/refreshed.Isn’t cool.


February 26, 2008 at 2:46 am |
It’s very useful for me..
thank you!
March 12, 2008 at 2:40 pm |
Thank you!
Another question?
Do you know the proceed for clear text, input, etc with data when I click a button?
or dou you know the proceed for reload a panel or another component?
I wait your answer!
Thanks!
March 13, 2008 at 10:15 am |
hi
your welcome,and about the question : if you want to clear the text in a TextInput control then do:
idTextInput.text=”";
This will clear the text on button click [as you require ] .
There is no way to reload a component, panel is a container which has our controls and hold the required ,so to reload there is a way like call a function and mention your code in it which you want to refresh like clear text and others like send services this will do i hope,The existing property of a component can be used “creationComplete” and call a function in it which will reset the controls.
comment for queries.
regards,
kumar.
March 31, 2008 at 1:01 pm |
yes! it works like a charm… but is it possible to refresh a canvas component alone?
To add more oil to the fire… the canvas component is actually one which is built as a separate screen.
Please try and give me some suggestions.
March 31, 2008 at 1:09 pm |
Reload the Canvas Component .
March 31, 2008 at 1:38 pm |
Its like this…
I have a view stack, and have a numbe of canvases under it.
and when the values in a tree changes, i have to reload the canvas accordingly.
March 31, 2008 at 1:39 pm |
And can i use the same code to reload a canvas component?
I cant right?
April 5, 2008 at 12:25 pm |
hi Ram,
read about Modules in Flex , they are very usefull when taking about different and seperated views, it will defenately solve the problem. your requirement.
regards,
kumar.
July 10, 2008 at 3:03 am |
i spent hours in flex getting my components to communicate and to clear data when they are not being used and reload data accordingly , within flex to speed things up, but a button that refreshes the page for you is beautifull. Takes a little longer then clearing memory directly in flex but , makes my life lots easier , so many thanx! i needed this!
August 6, 2008 at 10:00 am |
It’s great.
I Spent long time for refreshing… but failed
Thanks !!!!!!!!!
August 8, 2008 at 9:10 am |
Thanks a lot
This thing really works for me ..
Thanks Buddy
October 1, 2008 at 7:38 am |
This is very very good.
One more question, could we control the reload period? Such as in every two seconds we do the reload.
October 1, 2008 at 3:27 pm |
Yes its possible, there’s a post here on usage of Timer Class just refer that and using this Timer Class we can raise an event at specified Time interval. For you just call the function on the given interval, so that function will refresh the App.
Refer :: Timer Class and its methods.
Link for the Usage of Timer Class .
http://flexonblog.wordpress.com/2008/02/13/using-timer-class-in-flex/
Comment for any queries.
regards,
kumar.
October 2, 2008 at 2:02 pm |
Thanks Kumar.
It works!!!!!
November 4, 2008 at 3:53 pm |
Kumar,
Using javascript to reload/refresh app is elegant, and works! Many thanks for sharing…
November 12, 2008 at 1:40 pm |
Cheers dude, worked a treat.
Might be worth mentioning that this also works from anywhere in ActionScript:
flash.net.navigateToURL(ref, “_self”);
Noting that navigateToURL comes from flash.net
November 25, 2008 at 12:54 pm |
Hey it worked…Thanks a ton….
December 11, 2008 at 8:00 am |
Thanks dude!! This is helpful man
January 19, 2009 at 9:50 am |
I have try your solution. The page can be reload. However, after reload, my timer stop counting. What happened?Any solution?Thanks
January 20, 2009 at 10:08 am |
Hi,
After the reload the Application is re-initialized means everything starts over again.The Timer you are using also re-initializes.If you want to access the previous counter value you got to store the value for this use the SharedObjects concept[browser cookies in Flex]there are posts here in my blog.comment for queries.
regards,
kumar.
January 23, 2009 at 7:58 pm |
You are the MAN!!!
Thank you so much. You saved me tons of time trying to figure this out in actionscript for Flex 3 and I still would never have been successful.
You are a life saver.
Thanks,
-Jeff
February 26, 2009 at 4:03 pm |
hi kumargandhi!
thats cool that you post …
but can you help me ….
i have a problem when a flex app is reload i get an error becouse it secondary registraite the historyManager in creationComplete event , can you tell how can i know that that page wich hold flex app is reloaded inside flex app …if this posible or not inside flex app?
thanks
March 2, 2009 at 3:41 am |
Hi,
whole the App is reloaded, not part of it.
regards,
kumar.
March 25, 2009 at 10:18 am |
hi,
very useful tutorial, Thanks.
I’ve a question, by using javascript in flex, how to create a folder in desktop?
flex it’s not support ActiveXObject(“scripting.filesystemobject”); ?
anybady have any idea about create a folder in flex…..?
Thanks in advance.
prakash.
March 25, 2009 at 10:46 am |
Hi,
Flex can only give you limited access to the localsystem,so this is not possible.
regards,
kumar.
April 14, 2009 at 10:30 am |
Hi
Very useful tutorial and explain in a very simple manner. Thanx for upload such a helpful material.
Regards
Abbas Ali Butt
September 9, 2009 at 10:34 pm |
In my Project i have used module
loaders in viewsatck . When i did some operation in any module and go to
some other module ,when i come back to the previous module am able to see
the operations which i have done in this module. Am facing this problem
since many days . I want the data to be refreshed everytime i visit my
previous modules .