03-30-2005, 10:30 PM
|
#1
|
|
CookieDog
Join Date: Oct 2004
Posts: 107
|
Variables to Flash From Browser
I did a search, but could not quite find the right answer to my question. I need to have a variable from my HTML page sent to my Flash movie that is embedded in the same HTML page.
I tried doing this with parameters added to the URL, like this:
www.somewhere.com?param1=1¶m2=2
However, I couldn't figure out how to get the parameters into the Flash swf. I tried this code, but I couldn't get it to work:
Javascript code on HTML page:
Code:
<script language="JavaScript" type="text/JavaScript">
myHref = document.location.href;
myHrefParams = myHref.substr(myHref.indexOf('?'));
myContent = "<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'";
myContent += "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0'";
myContent += "WIDTH='100%' HEIGHT='100%' id='main' ALIGN=''>";
myContent += "<PARAM NAME=movie VALUE='main.swf'" + myHrefParams + "'><PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#FFFFFF>";
myContent += "<EMBED src='main.swf' quality=high bgcolor=#FFFFFF WIDTH='100%' HEIGHT='100%' NAME='main'";
myContent += "ALIGN='' TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer'></EMBED>";
myContent += "</OBJECT>";
document.write(myContent);
</script>
Then I tried to read the parameters sent with the URL in the Flash swf, but they never show up. All I get from the code below is the URL to the actual swf file (e.g., www.somewhere.com/main.swf). I really want the URL to the HTML page - the location.href - is there a way to read that in Flash?
ActionScript Code:
s = unescape (_URL);
ueURL = s.substr(s.indexOf ("?")+1,s.length);
myTestLine.text = ueURL;//Just for testing to see what I get
Any help is appreciated. Thanks!
Last edited by CookieDog; 03-30-2005 at 10:34 PM.
|
|
|
03-30-2005, 10:51 PM
|
#2
|
|
>Teaching in Progress<
Join Date: Mar 2005
Location: Serbia
Posts: 666
|
Didn't read your whole post, but your end is done wrong - Flash automatically parses parameters passed to it as GET-type query, and builds those variables on _level0
So, if you've printed the query nicely after the .swf name, and with example of http://www.somewhere.com/?param1=1¶m2=2 , in Flash you would be able to access those variables as:
ActionScript Code:
myTestLine.text = "param1: " + _level0.param1 + "\nparam2:" + _level0.param2;
Hope it helps...
|
|
|
03-31-2005, 03:31 AM
|
#3
|
|
CookieDog
Join Date: Oct 2004
Posts: 107
|
This didn't work. Wouldn't I have to do a LoadVars or something to get the variables as you describe?
Maybe you should read my entire post, and let me know if you see anything else.
Thanks!
|
|
|
03-31-2005, 03:35 AM
|
#4
|
|
Super Moderator
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
|
|
|
|
03-31-2005, 10:56 AM
|
#5
|
|
>Teaching in Progress<
Join Date: Mar 2005
Location: Serbia
Posts: 666
|
Yup, you can use 'FlashVars' as CyanBlue suggested, but they are supported only with Flash 6+ plugins, so if you aim 'old-plugin' market, or you want to cache the movie based on parameters passed to it, or you just want it the way you've tried to make, in HTML make something like:
Code:
<script language="JavaScript">
movieSize = [640,480];
movieURL = document.location.toString();
movieURL = movieURL.split("?");
movieURL = 'movie_name.swf?' + movieURL[1];
document.write('<object codeBase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + movieSize[0] + '" height="' + movieSize[1] + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">');
document.write('<param name="movie" value="' + movieURL + '">');
document.write('<param name="menu" value="true">');
document.write('<param name="quality" value="high">');
document.write('<param name="scale" value="exactfit">');
document.write('<embed src="' + movieURL + '" menu="true" scale="exactfit" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="' + movieSize[0] + '" height="' + movieSize[1] + '">');
document.write('</embed></object>');
</script>
Of course, make sure that movie_name.swf is replaced by name of your .swf file, and you have your movie's width and height in movieSize array...
This should (didn't test it, but that's the way to do it) print your specified flash movie passing to it all the variables on traditional way - GET-type query after the movie name...
After that, you should be able to access all the passed variables from _level0 ... e.g. if you've put this code in 'home.html' file, which loads some of your movies, if you call it with 'path/to/home.html?foo=bar', from your Flash move you should be able to access _level0.foo variable which would have 'bar' as value...
Hope it helps...
|
|
|
03-31-2005, 02:35 PM
|
#6
|
|
Super Moderator
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
|
Yup... That's got to work... But I hate that form... Don't know why, don't ask...
Just a quick question, Sx...
You have 'version=6,0,0,0' in the code... I don't know if that happened because you did copy and paste or not, but that's not importane...
If you have that string, it will look for the Flash Player on the user's computer to see if the version is greater or equal to that given version number and only display the Flash object when the condition is met and forward to Macromedia's page if not...
Can you see if what I have above is correct or not???
|
|
|
03-31-2005, 04:13 PM
|
#7
|
|
>Teaching in Progress<
Join Date: Mar 2005
Location: Serbia
Posts: 666
|
I've copied <object>/<embed> structure from the first HTML I've grabbed... I'm not crazy to type all that... Time is money
Anyways, that cab version doesn't matter much as I know in players older than 7,00,14 (or was some of the earlier versions able to auto-update), and certainly not to non-IE users (read it: normal, sane, non-masochistic people  )... So that param in RL is ignored (again, I'm not 100% sure about that - I wouldn't touch IE with a stick... not even in a radiation-proof suit... from 5 miles away)... But you feel free to try it and tell us what happens... Again, i think that even if you put 9,0,0,0 nothing would happen...
But if it's causing unneeded updates, well, it's easy to put it to 4,0,0,0 and 'no problemo'
Last edited by [Sx]; 03-31-2005 at 04:15 PM.
|
|
|
03-31-2005, 06:31 PM
|
#8
|
|
Super Moderator
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
|
Well... I tested with F5 player with the site that says 6.0.79.0 and it did not forward me to the Macromedia site... (I guess that site needs FPI or something...)
Also did a test with F6 player with the site that says 7.0.0.0 and it just played the movie... Wicked...
|
|
|
03-31-2005, 06:43 PM
|
#9
|
|
>Teaching in Progress<
Join Date: Mar 2005
Location: Serbia
Posts: 666
|
Told you, cab version has nothing to do with it... Maybe only with 7.xx players that have auto-update ability, but I'm not sure about that one either...
Epilogue: Don't doubt in Sx' judgement
|
|
|
03-31-2005, 08:24 PM
|
#10
|
|
CookieDog
Join Date: Oct 2004
Posts: 107
|
Okay, I got it to work. My problem was pretty simple - I had an extra quote or two where I was trying to concatenate my variable as part of the movie swf name (doh!).
Anyway, my original way of doing it worked, as well as just reading the variables from _level0. (Thx)
But, now how would I get this information to be updated from the URL (location.href - NOT the path to my swf movie), without actually going to a new HTML page or swf? Is there a way to do that?
For example, when I use anchors for the Back Button in Flash, the URL actually changes like this:
www.abc.com/index.html#anchor1
www.abc.com/index.html#anchor2, etc.
Would I be able to read that URL, and send the variable of the anchor name to my swf movie as it changes (not just the first one, which is what it does now, without updating)?
|
|
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 08:09 AM.
///
|
|