Hi all!
I have a problem with my AS3 code, obviously…
I am trying to get my PHP variables from my load.php document to my flash-document.
That all works fine and I am able to get my data down to flash variables inside my function.!
But, I would like to be able to access this data from outside of this function which gets the data - unfortunately I cant, or… Don’t know how to. I hope that you are able to shed a light upon my problem.
Please have in mind that this is my 1. actionscript code ever to complete a fightning system on my php webpage
So here goes, this is my code:
var myLoader:URLLoader = new URLLoader()
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES
myLoader.load(new URLRequest("load.php"))
myLoader.addEventListener(Event.COMPLETE, onDataLoad)
myLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError)
myLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError)
myLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPStatus)
function onDataLoad(evt:Event){
var VariableName = evt.target.data.VariableName;
var VariableName2 = evt.target.data.VariableName2;
Title_txt.text = VariableName ; // This is where I use my code - this one works!
}
function doSomething(e:Event = null):void{
Title_txt.text = VariableName2 ; // This should change the value of my textbox but dont! It's not giving any errors - just wont get the value.. :s :s .
}
doSomething();
//error callbacks
function onIOError(evt:IOErrorEvent){
trace("IOError: "+evt.text)
}
function onHTTPStatus(evt:HTTPStatusEvent){
trace("HTTPStatus: "+evt.status)
}
function onSecurityError(evt:SecurityErrorEvent){
trace("SecurityError: "+evt.text)
}
I have written 2 comments in the code where I see the difference in the result…
I cant seem to get the value of my variable as soon as I am on the other side of the “}” which closes the function: function onDataLoad(evt:Event){…
I hope I have made the problem clear but feel free to ask about anything at all!
Thx!
Regards
SilenceWar