Pass variable from JavaScript to ActionScript to load FLV clip

How can I pass a variable from JavaScript to ActionScript so that I can load different FLV clips with the same SWF file?

Currently, I use FlashVars within the HTML Flash Object tag to pass the variable, and in the SWF file I set up a variable to pass to the SWF Parameters for the video clip source. The source field is left blank in the SWF videoclip, but I have used ActionScript to set the source, and I call the video object "mymovie".

I have tested the ActionScript with manually setting the mymovie source to the appropriate file, and it works perfectly. But when I try to pass a variable to it from JavaScript, it is not found.

In the HTML file, I use FlashVars in the OBJECT tag, as follows:
<param name="FlashVars" value="mymoviesource=http://mysite.com/mymovie.flv">

In the SWF file, I use:
mymovie.source=this.root.mymoviesource
pdbenAsked:
Who is Participating?
 
Aneesh ChopraCommented:
In ActionScript 2, these variables were simply defined as variables in _root.
This has changed for ActionScript 3. Now these variables are accessible in a parameters object located in the root loaderInfo object.

you need to change following code:
-------------------------------
mymovie.source=root.mymoviesrc;
-------------------------------

change it to following:
-------------------------------
mymovie.source=root.loaderInfo.parameters.mymoviesrc;
stop();
-------------------------------


-------------------
Aneesh Chopra
-------------------
0
 
Aneesh ChopraCommented:
Problem is in following code, where u trying to access passed variable:

mymovie.source=this.root.mymoviesource

it should be like this:

mymovie.source=_root.mymoviesource


-------------------
Aneesh Chopra
-------------------
0
 
pdbenAuthor Commented:
I tried this, but now I get the error:

ReferenceError: Error #1065: Variable _root is not defined.
      at mymovie_fla::Symbol1_1/mymovie_fla::frame1()
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
najhCommented:
are you using Flash CS3?

I wonder if _level0 might work in place of _root...
0
 
pdbenAuthor Commented:
I am using Flash CS3.

I made the change to _level0 but got the same error.
0
 
Aneesh ChopraCommented:
in FLASH CS3

try following code:

mymovie.source=root.mymoviesource


only change is only "root" instead of "this.root"
0
 
pdbenAuthor Commented:
That didn't work either.
0
 
Aneesh ChopraCommented:
I suggest if you can upload ur FLA for review
0
 
pdbenAuthor Commented:
OK, here is everything zipped and uploaded.

You can download it at http://ourbeasley.com/media/kids/2007/mykids.zip

For simplicity, everything is located and referenced in the same directory.
0
 
pdbenAuthor Commented:
Has anybody been able to check out the zipped file I uploaded for any answers (see above)?
0
 
pdbenAuthor Commented:
Nobody has responded to this in almost a week, so I have resubmitted the question as a new question.
0
 
pdbenAuthor Commented:
Thanks, that did the trick!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.