tom variabel
HejJeg har et problem håber i kan hjælpe.
Jeg har dette kode i frame 1
var currentTagString = "";
var nameString = "";
function getNameFromTag():{
var variables:URLVariables = new URLVariables("tag="+currentTagString);
var request:URLRequest = new URLRequest();
request.url = "http://www.iolite.dk/getnamefromtag.php";
request.method = URLRequestMethod.POST;
request.data = variables;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, completeHandler);
try
{
trace("trying..")
loader.load(request);
}
catch (error:Error)
{
trace("Unable to load URL");
}
}
function completeHandler(event:Event):void {
trace("complete");
var loader2:URLLoader = URLLoader(event.target);
loader2.dataFormat = URLLoaderDataFormat.VARIABLES;
var variables2:URLVariables = new URLVariables(loader2.data);
var temp:String = String(variables2);
trace(temp); // just to check the "raw" data
var temp2 = unescape(temp);
var temp3 = unescape(temp2);
nameString = temp3.substring(4,temp.length);
trace("Hej "+ nameString);
}
function reportKeyDown(event:KeyboardEvent):void
{
var keyCode = event.keyCode;
if ((keyCode >= 48 && keyCode <= 57)||
(keyCode >= 65 && keyCode <= 90)) { // numbers or letters
currentTagString += String.fromCharCode(keyCode);
}
if(keyCode == 13){ //enter pressed
trace("tag: "+currentTagString);
getNameFromTag();
//mySQLTest();
//ASQL();
gotoAndPlay(91);
currentTagString = "";
}
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);
Jeg skal så senere i frame 91 bruge variablen nameString som skal vise indholdet af denne i et tekstfield, frame 91 kode ser sådan ud:
var writingCompleted:TextField = new TextField;
writingCompleted.autoSize = "center";
writingCompleted.x =200;
writingCompleted.y= 200;
writingCompleted.text = nameString;
addChild(writingCompleted);
Men indholdet af nameString er tomt, hvorfor det?
jeg bruger as3