View Full Version : how to use flashvars in as3
atnok
11-03-2006, 09:36 AM
hi,
I searched livedocs and many forums about actionscript 3. In as3 it was really easy to receive parameters from the embed code. i only used the _root-variables to get the parameters i needed. in as3 its not that simple. I made a actionscript-project in Flex with only one class:
package {
public var userid:String;
public class testClass extends MovieClip()
{
public function testClass()
{
// in as2 i got the userid like that
userid = _root.userid;
// in as3???
}
}
}
can anyone help me with that simple question?
CDHBookingEdge
11-03-2006, 11:06 AM
See if this helps: ActionScript 2 Migration (http://livedocs.macromedia.com/flex/2/langref/migration.html)
Here's what they say in there about _root:
AS2.0 AS3.0 equivalent Comment
===== ======================== =====================
_root flash.display.DisplayObject.stage Removed. The closest
equivalent is the Stage,
which serves as the root
of the ActionScript 3.0
display list.
Hope that helps,
Christopher
CDHBookingEdge
11-03-2006, 11:11 AM
Well that editing job pretty much sucked huh?
Let me try it another way.
ActionScript 2.0: _root
ActionScript 3.0 equivalent: flash.display.DisplayObject.stage (http://livedocs.macromedia.com/flex/2/langref/flash/display/DisplayObject.html#stage)
Comments: Removed. The closest equivalent is the Stage, which serves as the root of the ActionScript 3.0 display list.
Phew! There, that's a lot prettier looking LOL
Christopher
atnok
11-03-2006, 11:36 AM
hi,
thanks. i tried that. the problem is that stage is a DisplayObject.
i tried:
userid = stage.userid;
userid = root.userid;
userid = stage.root.userid;
i always get that error:
1119: Access of possibly undefined property userid through a reference with static type flash.display:DisplayObject.
atnok
11-03-2006, 04:19 PM
i discovered the problem: like this it works fine:
AS3:
package {
public var userid:String;
public class testClass extends MovieClip()
{
public function testClass()
{
userid = root.loaderInfo.parameters.userid;
}
}
}
HTML:
<embed
src="testClass.swf"
quality="high"
bgcolor="#000000"
width="500" height="300"
flashvars="userid=123456"
scale="noscale"
salign="l"
name="testClass"
align="middle"
play="true"
loop="false"
quality="best"
allowScriptAccess="always"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
CDHBookingEdge
11-04-2006, 01:04 PM
Cool glad you found it ;-) And I promise I won't send you the link that says that using root is the "root of all evil" ;-)
atnok
11-04-2006, 02:49 PM
I don't really understand what you mean? do i have to? thank you anyway for your help.
CDHBookingEdge
11-05-2006, 07:41 PM
I was joking around..when I did a google search I came up on one entry that had an article saying that you should never use _root(now root it seems). It was just a joke.
;-)
sooty
10-05-2007, 09:35 AM
i discovered the problem: like this it works fine:
AS3:
package {
public var userid:String;
public class testClass extends MovieClip()
{
public function testClass()
{
userid = root.loaderInfo.parameters.userid;
}
}
}
HTML:
<embed
src="testClass.swf"
quality="high"
bgcolor="#000000"
width="500" height="300"
flashvars="userid=123456"
scale="noscale"
salign="l"
name="testClass"
align="middle"
play="true"
loop="false"
quality="best"
allowScriptAccess="always"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
Hi just trying to implement your code, and i can't get it to compile, surely the AS3 should be like this
package {
import flash.display.MovieClip;
public class testClass extends MovieClip {
public var userid:String;
public function testClass()
{
userid = root.loaderInfo.parameters.userid;
}
}
}
If written like this and compiled without error the userid var returns null, have I missed something?
theGlassBeadGame
12-09-2008, 02:05 PM
Hi Sooty,
Did you ever get to the bottom of this? I'm grappling with the same problem right now.
Thanks
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.