Reputation: 36107
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>
Upvotes: 0
Views: 814
Reputation: 25489
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 makes loadcomplete
false, 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.COMPLETE
event.
Tell it to the IDE like this:
Near your class declaration, add the metadata and make your class extend EventDispatcher
//Imports and package declaration
[Event(name="complete", type="flash.events.Event")]
public class YourClassName extends EventDispatcher {
//Remaining part of class here
Then, in your loadcompletefun
, add this
dispatchEvent(new Event(Event.COMPLETE));
And, in the place you call clickfun
, do this:
o=new YourClassName();
o.addEventListener(Event.COMPLETE, gp);
and, declare gp
as
private function gp(e:Event):void {
trace(getpath());
//You now have the ability to call getpath()
}
Upvotes: 1
Reputation: 39408
Based on a review of the code, I'm guessing you are receiving an error because the loadcomplete and urlpath variables are not defined. so, make sure you define it in your ActionScript block:
public var loadcomplete : Boolean
public var urlPath : String
Also make sure that you define languagecode and Defaultlanguagecode as variables using the same approach.
Any one of these omissions could cause a compile time or runtime error.
Upvotes: 0