Refresh/Reload Flex App using JavaScript code.
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:10 pm
like remove it and popit [This may not be the best practice]
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.
The part i did not understand is, what do you mean by pop it?
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.