View Full Version : Passing variables from HTML to Flash
bgflasher
March 26th, 2009, 05:47 AM
Hello!
I am sure this topic is already discussed here but I really can't find it.
So, what I wanna do is to manipulate my flash code through HTML.
My application should have two variants - with panel and without panel.
I want to tell Flash to make my panel visible only if there is "yes" parameter in the HTML code. I am doing it with FlashVars. I know there is way to make it so:
<embed src="myMovie.swf?panel=yes">.
Anyway, this is what i do in the HTML code:
<param name=FlashVars value="addPanel=yes">
<embed src="myMovie.swf" name="FlashVars" FlashVars = "yes" quality="high" bgcolor="#ffffff" width="500" height="280" name="FlashVars"
And now my actionscript:
this.loaderInfo.addEventListener(Event.COMPLETE, loaderComplete);
function loaderComplete(e:Event):void{
var FlashVars=this.loaderInfo.parameters;
if(FlashVars.addPanel == "yes"){
panel.visible = true;
}else{
panel.visible = false;
}
}
When I start the application on a browser Flash makes no difference between "yes" and "no" parameter so I am doing it wrong. That's my first time passing variables from html to flash and it's a bit hard to understand. So any help would be appreciated :)
bonnieraymond
March 26th, 2009, 06:08 AM
quick reply:
in HTML:
FlashVars = "addPanel=yes"
in AS3:
panel.visible = (root.loaderInfo.parameters.addPanel=="yes");
bgflasher
March 26th, 2009, 06:16 AM
quick reply:
in HTML:
FlashVars = "addPanel=yes"
in AS3:
panel.visible = (root.loaderInfo.parameters.addPanel=="yes");
Thanks, I am trying it now.
bgflasher
March 26th, 2009, 09:07 AM
Nope,
I can't get it working. Any other ideas.
m90
March 26th, 2009, 09:15 AM
Why don't you pass the parameter like "myMovie.swf?panel=yes" and use "root.loaderInfo.parameters.panel" to access the parameter at runtime?
bgflasher
March 26th, 2009, 10:05 AM
Yes, i tried with Query String too.
I think there are no mistakes on my code but it's still not working.
m90
March 26th, 2009, 10:22 AM
But what exactly happens at "trace(root.loaderInfo.parameters.panel)"?
What browser are you using and how do you embed the swf exactly?
bgflasher
March 26th, 2009, 10:35 AM
using query string:
<param name="movie" value="myMovie.swf?panel=no" />
<embed src="myMovie.swf?panel=no" ... />
And this is my AS code:
this.loaderInfo.addEventListener(Event.COMPLETE, loaderComplete);
function loaderComplete(e:Event):void{
var queryString=this.root.loaderInfo.parameters;
if(queryString.panel == "no"){
header.visible = false;
}
}
When I trace this.root.loaderInfo.parameters.panel it returns me 'undefined'.
Thanks for trying to help :)
m90
March 26th, 2009, 11:52 AM
Ok, so first you don't need to wait for the loader to complete when looking for a query string (it will be present as soon as the swf is starting) & second I think the problem is that "this" in your context is not definded. Just use this:
var queryString:String = root.loaderInfo.parameter.panel;
bonnieraymond
March 26th, 2009, 01:40 PM
indeed, because the mc you're trying to load might not be added to stage yet, so its root would become undefined.
bgflasher
March 27th, 2009, 09:23 AM
I am out of ideas. I tried this but "root.loaderInfo.parameters.panel" always returns 'undefined'.
Is "root.loaderInfo.parameters.panel" enough to connect the HTML part with AS?
m90
March 27th, 2009, 09:42 AM
It should definitely be working this way.
Maybe it's a browser thing? I've seen the strangest things especially with IE. Have you tried it on other browsers / platforms / servers?
Or there's something else in you AS. Can you post the whole code you're using?
bgflasher
March 27th, 2009, 09:49 AM
Yes, sure.
//passing variables through HTML
var queryString:String = root.loaderInfo.parameters.panel;
trace(root.loaderInfo.parameters.panel); //undefined
trace(queryString);//normally, null
if(queryString == "no"){
header.visible = false;
}
HTML code:
<param name="movie" value="audioPlayer.swf?panel=no" />
<embed src="audioPlayer.swf?panel=no" quality="high" ... />
bonnieraymond
March 27th, 2009, 05:49 PM
first of all, try to trace(root) if it return a non-undefined value
bgflasher
March 30th, 2009, 04:16 AM
OK.
It returns [object MainTimeline].
bgflasher
April 1st, 2009, 10:10 AM
Hi again.
I solved the problem. And yes, it was very confusing.
What you guys told me was wrong and is not supported by Actionscript 3.0. In as3 you can't use vars after .swf (queryString). You must use 'flashvars' in the RunActiveContent.
So what you should do in the HTML is:
<script language="javascript">
...
AC_FL_RunContent(
...
'movie', 'myMovie',
'flashvars','panel=no',
...
); //end AC code
}
</script>
And then in Flash CS3 you should write:
var queryString:String = this.loaderInfo.parameters.panel;
if(queryString == "no"){
header.visible = false;
}
So, what is happening here? as3 reads 'flashvars' parameter from the HTML file and if my query string is equal to 'no' it executes the rest of our code.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.