|
-
Parsing Query string in js to pass to swf
I'm trying to pass a variable into an swf using query strings. Am loading the swf through swfobject.js in my aspx page.
Code:
<div id="flashcontent">Replacement copy</div>
<script type="text/javascript">
var myVar = new SWFObject("mymovie.swf", "name", "740", "540", "8", "#ffffff");
so.addVariable("varInFlash", "<%=Request.QueryString["variableName"]%>");
myVar.write("flashcontent");
</script>
with a
in the first frame of my movie.
Only problem is, that with the so.addVariable statement in there, the swf doesn't load. I comment out that line, and it loads just fine.
So I have syntax off somehow? I think for asp that the brackets [ ] are needed, but not sure.
Or is my javascript syntax off??
Anyone here have some input?
THANKS!
-
Bearded (M|G)od
What version of SWFObject are you using?
-
swfobject
had gone to googlecode to get latest, but let me double check...
-
Bearded (M|G)od
If you're using the latest, 2.x series, you're using the completely wrong syntax. Syntax has changed from 1.5 to 2.0. Revise your code, and then we'll take a better look at it.
-
Ah! Had 1.5 but then that wasn't working, so grabbed a temp copy of 2.2.
That would explain a lot!
-
Okay, got it working with 2.2 and
Code:
<param name="flashvars" value=<%=Request.QueryString%> />
simple.
Don't know why original request was failing with 1.5, but guess it doesn't matter as have moved on to 2.2.
Thanks for help!!
-
Bearded (M|G)od
Wait, why are you using a <param> tag with 2.2? Your code should be similar to:
swfobject.embedSWF(....);
-
Ha!
You are absolutely right, and that is how I started writing it.
Then I noticed the "SWFObject 2 HTML and JavaScript generator v1.2" and tried to figure out why that was being distributed if it produced different code.
So I ran with it.

I got it to work (which is more than I can say with what I thought was supposed to work with 1.5), so now I'm backing out to the swfobject.embedSWF(....); code.
-
So basically,
Code:
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
swfobject.embedSWF("movie.swf", "swfWin", "400", "300", "8.0.0", flashvars, params, attributes);
</script>
</head>
<body>
<div id="swfWin">
SWF goes here
</div>
</body>
is the proper way to do it, and I just have to pass the query to flashvar.
-
Bearded (M|G)od
flashvars, params, and attributes are objects that you need to define.
To short hand it, you can just use {} to fill the gap if there's nothing needed.
In your case, you could do this:
Code:
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
swfobject.embedSWF("movie.swf", "swfWin", "400", "300", "8.0.0", "expressInstall.swf", {varInFlash: "<%=Request.QueryString["variableName"]%>"}, {}, {});
</script>
</head>
<body>
<div id="swfWin">
SWF goes here
</div>
</body>
-
Bearded (M|G)od
Ha, and I just now looked at your original attempt again. I see what was wrong. You had your variable names mixed up. You started out defining a myVar, then when you call the addVariable, you used so. If you changed it to
Code:
myVar.addVariable("varInFlash", "<%=Request.QueryString["variableName"]%>");
it should work.
-
Working with Flashvars
I have tried n no of ways to access flash vars in as3.
Anyone here have some input?
THANKS!
That would explain a lot!
-
 Originally Posted by MyFriendIsATaco
Ha, and I just now looked at your original attempt again. I see what was wrong. You had your variable names mixed up.
Duh! I was so focused on "maybe I have a delimter wrong" or thinking that the syntax wasn't right, that I didn't even notice that.
But then again no one noticed that until you just did...

But with that correction, it is producing an "identifier expected" error within the request.
Code:
__w.Write(Request.QueryString["variableName"])
~
I thought the Request.QueryString was properly formed?
-
Bearded (M|G)od
I know nothing about ASP or .NET. I'm purely a PHP/Python guy. Anti-Microsoft. 
@prj To access FlashVars in AS3, do:
Code:
root.loaderInfo.parameters.myFlashVar
-
Bearded (M|G)od
Hmm, accord to this page: http://www.w3schools.com/ASP/coll_querystring.asp
You syntax should be: Request.QueryString("variableName")
Parenthesis vs square brackets.
-
 Originally Posted by MyFriendIsATaco
Yeah, not an asp guy myself. Just helping out on this. Good learning situation.
And I read somewhere that the square brackets have to be used on asp. What I was doing wasn't working, so I changed them to square brackets and stopped getting an error. Of course, now that I'm getting into it, I'm finding a lot of things I read about in researching this have just been plain wrong.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|