I going to call only “clickfun()” method i need urlPath value after success service return value. but it throws stack overflow errors. Any help please.
private function clickfun(eve:Event):String{
languagecode = "assets/myFont_en.swf";
Defaultlanguagecode = "assets/myFont_default.swf";
var request:URLRequest = new URLRequest(languagecode);
var xmlURLLoader:URLLoader = new URLLoader(request);
xmlURLLoader.addEventListener(Event.COMPLETE,loadcompletefun);
xmlURLLoader.addEventListener(IOErrorEvent.IO_ERROR,ioerrorFun);
xmlURLLoader.load(request);
return getpath();
}
private function getpath():String{
if(loadcomplete == true){
Alert.show(urlpath);
return urlpath;
}else
return getpath();
}
private function loadcompletefun(e:Event):void{
loadcomplete = true;
urlpath = languagecode;
}
private function ioerrorFun(e:IOErrorEvent):void{
loadcomplete = true;
urlpath = Defaultlanguagecode;
}
<mx:Panel title="Embedded Fonts Using ActionScript" width="800" height="500">
<mx:Button label="Click" id="btn" click="clickfun(event)"/>
</mx:Panel>
The obvious with your remote interaction code is that loaders load data asynchronously. This means that the execution of the program continues while the loaders load data on a (virtually) different thread.
The issue is here you call
getpath()right after you have started the load. This makesloadcompletefalse, and the getpath function keeps recursing and the stack overflows.What you SHOULD so is:
Let your class dispatch an event. Say you dispatch just a
Event.COMPLETEevent.Tell it to the IDE like this:
Near your class declaration, add the metadata and make your class extend EventDispatcher
Then, in your
loadcompletefun, add thisAnd, in the place you call
clickfun, do this:and, declare
gpas