Link to home
Start Free TrialLog in
Avatar of moonshot
moonshot

asked on

Simple URL variables question

This should be fairly simple.  I have a dynamic text instance called pid_txt.  My actionscript, on the one and only frame I have, is:

pid_txt.text = pollid;

Here's my object/embed tag:

[CODE]
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="285" height="200" id="poll_v1" align="middle">
      <param name="allowScriptAccess" value="sameDomain" />
      <param name="allowFullScreen" value="false" />
      <param name="movie" value="poll_v1.swf?pollid=1" />
      <param name="quality" value="high" />
      <param name="bgcolor" value="#ffffff" />
      <embed src="poll_v1.swf?pollid=1" quality="high" bgcolor="#ffffff" width="285" height="200" name="poll_v1" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
      </object>
[/CODE]
Avatar of Savong
Savong
Flag of United States of America image

Does trace give you the correct output?  Since you haven't really described what's wrong it's a little hard to troubleshoot.
Avatar of moonshot
moonshot

ASKER

Sorry, the problem is that I can't read the value correctly.  I can't use trace because I'm reading the value of a url.  I thought you could only use trace when you run it from flash itself.
True, hadn't thought about that part.  Does the textfield have the correct name on it?  Can you assign a static value to it?  i.e. pid_txt.text = "Testing".
Add _root in front to see if it works...

pid_txt.text = _root.pollid;

CyanBlue
I've changed it up a bit.  Actionscript now looks like this..

var passed:String = _root.pollid == undefined ? "Nothing Passed" : _root.pollid;
pid_txt.text = passed;

however, I'm getting "Access of undefined property _root" errors.  If I take off the _root, gives the same error only with pollid.

BTW, I'm using ActionScript 3.0.
AS 3.0 is going to make a difference.  I found this code, hopefully it helps:
http://snipplr.com/view/2864/get-documents-url-arguments-and-flashvars-aka-parameters/
Hmm, that helped.  Now I've got this...

try {
    var keyStr:String;
    var valueStr:String;
    var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
    pid_txt.text = paramObj["pollid"];
} catch (error:Error) {
    pid_txt.text = error.message;//"err";
}

and I get "Error" written to my dynamic text.
Have you tried using documentRoot instead of this.root.loaderInfo?  At this point I'd guess the LoaderInfo isn't being instantiated correctly.
Hmm, I'm still pretty new to AS.  How would I use documentRoot?
Try changing this line:
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;

to this:
var paramObj:Object = LoaderInfo(documentRoot.loaderInfo).parameters;

and try
pid_txt.text=paramObj;

and see what it reads then.

Savong:  It says undefined property documentRoot.  It also doesn't like the paramObj on the second line, but I think that can be fixed.
Sorry this is taking so long, I'm still getting familiar with the loaderInfo in AS3 myself.  The following code worked fine for me:
pid_txt.appendText("params:" + "\n");
try {
    var keyStr:String;
    var valueStr:String;
    var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
    pid_txt.appendText(paramObj["pollid"]);
} catch (error:Error) {
    pid_txt.appendText(error.message);
}

It's adapted from:
http://blogs.adobe.com/pdehaan/2006/07/using_flashvars_with_actionscr.html
Hmm, getting closer.  Here is my embed/object tag.  I'm getting an error stating the text must be non-null.

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="285" height="400" id="poll_v1" align="middle">
      <param name="allowScriptAccess" value="sameDomain" />
      <param name="allowFullScreen" value="false" />
      <param name="FlashVars" value="pollid=2" />
      <param name="movie" value="poll_v1.swf" />
      <param name="quality" value="high" />
      <param name="bgcolor" value="#ffffff" />      
      <embed src="poll_v1.swf" FlashVars="pollid=1" quality="high" bgcolor="#ffffff" width="285" height="400" name="poll_v1" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
      </object>
So a copy/paste of my code above still gave that error?  You could try specifying it with poll_v1.swf?pollid=2 instead of using a FlashVar, but really that shouldn't make a difference.  The code I pasted above worked properly in my tests and output the variable.  Would it be possible for me to look at the files you're working with?
Sure, grab them from dev.saesoe.com/flash/poll_v1.fla and poll_v1.html

There's a bunch of other crap in there you can ignore.  Also, feel free to give me suggestions on anything else, but keep in my I'm just playing around right now.
ASKER CERTIFIED SOLUTION
Avatar of Savong
Savong
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That was it.  Thanks.