Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Pass Variables into AS3 through Query String?

Explorer ,
Mar 05, 2010 Mar 05, 2010

Man! I've been searching ferociously and can't seem to find a solution that works for me. I am trying to pass variables via query string on a PHP page to Flash, and then have the swf add movie clips to the stage depending on the information it receives.

Here is what the PHP outputs:

swfobject.embedSWF("flash/detailScore.swf?a=0-0&b=0-0&c=30-54&d=30-20&e=42-18", ...

And here is my AS3 code:

function loaderInfoSh(e:Event):void{

var myQueryStrings=this.loaderInfo.parameters;
a = myQueryStrings.a;
b = myQueryStrings.b;
  c = myQueryStrings.c;
d = myQueryStrings.d;
e = myQueryStrings.e;
addTheResults(a,1);
addTheResults(b,2);
addTheResults(c,3);
addTheResults(d,4);
addTheResults(e,5);
}
this.loaderInfo.addEventListener(Event.COMPLETE, loaderInfoSh);


The addTheResults function takes the coordinates, adds a MC instance to the stage and positions it accordingly.

var colorMCArray:Array = new Array();

function addTheResults(val,colnum:Number){

if(val == null){val = "52-46";} // so I can test it locally


var daColor:String;

switch (colnum){
case 1:
daColor = "f3951c";
break;

case 2:
daColor = "74b47d";
break;

case 3:
daColor = "436494";
break;

case 4:
daColor = "9b74ac";
break;

case 5:
daColor = "b43d44";
break;
}

var dash:int = val.indexOf("-");
var lateral = val.slice(0,dash);
var vertical = val.slice(dash+1);

lateral --;
vertical --;

// adding the MC instance

var comm:tileB = new tileB();
comm.name = "comm"+colnum;
addChild(comm);
colorMCArray[colnum] = comm;

//Change the color

var colorTransform:ColorTransform = colorMCArray[colnum].transform.colorTransform;
var thiscolor = "0x"+daColor;
colorTransform.color = thiscolor;
colorMCArray[colnum].transform.colorTransform = colorTransform;
colorMCArray[colnum].x = 5;
colorMCArray[colnum].y = 536;
colorMCArray[colnum].x += (lateral * 9);
colorMCArray[colnum].y += (vertical * 9)*-1;
colorMCArray[colnum].addEventListener(MouseEvent.MOUSE_OVER, btnro);
colorMCArray[colnum].addEventListener(MouseEvent.MOUSE_OUT, btnrout);
}


I don't know what I'm doing wrong here.

TOPICS
ActionScript
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Mar 05, 2010 Mar 05, 2010

Was this the "e" in the code below you were pertaining to as the culprit? "e" is not a keyword. It's just the shortcut for the word "event" for the variable name of type Event which is the Event object that triggered the call of function loaderInfoSh. In your code you assigned e = myQueryString.e which should have given you a type mismatch error.

function loaderInfoSh(e:Event):void{
 
 var myQueryStrings=this.loaderInfo.parameters;
 a = myQueryStrings.a;
 b = myQueryStrings.b;
  c = myQueryString

...
Translate
Explorer ,
Mar 05, 2010 Mar 05, 2010

Ok, nevermind. One of my variables was the culprit. I had a variable named "e" that I renamed t "em" and it works now. Perhaps "e" is a keyword or something?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 05, 2010 Mar 05, 2010
LATEST

Was this the "e" in the code below you were pertaining to as the culprit? "e" is not a keyword. It's just the shortcut for the word "event" for the variable name of type Event which is the Event object that triggered the call of function loaderInfoSh. In your code you assigned e = myQueryString.e which should have given you a type mismatch error.

function loaderInfoSh(e:Event):void{
 
 var myQueryStrings=this.loaderInfo.parameters;
 a = myQueryStrings.a;
 b = myQueryStrings.b;
  c = myQueryStrings.c;
 d = myQueryStrings.d;
 e = myQueryStrings.e;
 addTheResults(a,1);
 addTheResults(b,2);
 addTheResults(c,3);
 addTheResults(d,4);
 addTheResults(e,5);
 }
this.loaderInfo.addEventListener(Event.COMPLETE, loaderInfoSh);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines