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-ae 6d-11cf-96 b8-4445535 40000" 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="sameDom ain" allowFullScreen="false" type="application/x-shockw ave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
[/CODE]
pid_txt.text = pollid;
Here's my object/embed tag:
[CODE]
<object classid="clsid:d27cdb6e-ae
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="poll_v1.swf?pollid=
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<embed src="poll_v1.swf?pollid=1"
</object>
[/CODE]
Does trace give you the correct output? Since you haven't really described what's wrong it's a little hard to troubleshoot.
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
pid_txt.text = _root.pollid;
CyanBlue
ASKER
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.
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/
http://snipplr.com/view/2864/get-documents-url-arguments-and-flashvars-aka-parameters/
ASKER
Hmm, that helped. Now I've got this...
try {
var keyStr:String;
var valueStr:String;
var paramObj:Object = LoaderInfo(this.root.loade rInfo).par ameters;
pid_txt.text = paramObj["pollid"];
} catch (error:Error) {
pid_txt.text = error.message;//"err";
}
and I get "Error" written to my dynamic text.
try {
var keyStr:String;
var valueStr:String;
var paramObj:Object = LoaderInfo(this.root.loade
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.
ASKER
Hmm, I'm still pretty new to AS. How would I use documentRoot?
Try changing this line:
var paramObj:Object = LoaderInfo(this.root.loade rInfo).par ameters;
to this:
var paramObj:Object = LoaderInfo(documentRoot.lo aderInfo). parameters ;
and try
pid_txt.text=paramObj;
and see what it reads then.
var paramObj:Object = LoaderInfo(this.root.loade
to this:
var paramObj:Object = LoaderInfo(documentRoot.lo
and try
pid_txt.text=paramObj;
and see what it reads then.
ASKER
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.loade rInfo).par ameters;
pid_txt.appendText(paramOb j["pollid" ]);
} catch (error:Error) {
pid_txt.appendText(error.m essage);
}
It's adapted from:
http://blogs.adobe.com/pdehaan/2006/07/using_flashvars_with_actionscr.html
pid_txt.appendText("params
try {
var keyStr:String;
var valueStr:String;
var paramObj:Object = LoaderInfo(this.root.loade
pid_txt.appendText(paramOb
} catch (error:Error) {
pid_txt.appendText(error.m
}
It's adapted from:
http://blogs.adobe.com/pdehaan/2006/07/using_flashvars_with_actionscr.html
ASKER
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-ae 6d-11cf-96 b8-4445535 40000" 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="sameDom ain" allowFullScreen="false" type="application/x-shockw ave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
<object classid="clsid:d27cdb6e-ae
<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="sameDom
</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?
ASKER
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That was it. Thanks.