and so on,
another, all in one string as below
returnString = “&var1=”.$var1."&var2=".$var2."&"; and whatever I could think of.
(this worked in AS2 sendAndLoad very well but here I am grappling with AS3.)
I keep getting the following error.
TypeError: Error #2007: Parameter text must be non-null.
at flash.text::TextField/set text()
at AS3_swf_php_comm_fla::MainTimeline/AS3_swf_php_comm_fla::frame1()
You have to set your .text properties in completeHandler. Your var variables only exist there, and aren’t defined until after the php variables load. You know when it loads within completeHandler.
You are right but I had tried by defining the variables var1, var2 and var3 at the very beginning of the program ( lines 1,2 and 3) and then shifting the .text variables outside. Nogo.
I have also tried by keeping them within the completeHandler function but the result was the same.
Its not just scope, its also timing. Putting the vars at the top of the page would fix the scope (access to use the variables) but not the timing (the point in time in which they’re defined).
The reasons callbacks are used in things like URLLoader.load() is because the loading of a remote document takes time, and other code shouldn’t have to wait for that load to happen to keep running. So instead of halting all code that could run during a load, that code is allowed to run and the code that needs to react to the completion of the load is contained within a callback that gets executed when the document loaded.
Anything in the same frame outside of the callback gets run before the callback, even if its written after the callback.
// RUNS FIRST ...
var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("comm.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
variables.user1 = "Guest";
variables.user2 = "Newbie";
variables.sendRequest = "parse";
varLoader.load(varSend);
varLoader.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(event:Event):void
{
// RUNS THIRD, after all other code already ran ...
trace(event.target.data.var1);
var var1 = event.target.data.var1;
var var2 = event.target.data.var2;
var var3 = event.target.data.var3;
}
// RUNS SECOND (or as part of FIRST) ...
// vars have _not_ been set to any values yet
str1.text = var1;
str2.text = var2;
str3.text = var3;
Its not just scope, its also timing. Putting the vars at the top of the page would fix the scope (access to use the variables) but not the timing (the point in time in which they’re defined).
Yes that occurred to me too, after I had just posted the last reply and was going through it. But thanks for the further clarification all the same. Much obliged !!
Thank you
Creating engaging and entertaining content for designers and developers since 1998.