• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 871
  • Last Modified:

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
0
pdben
Asked:
pdben
  • 7
  • 4
1 Solution
 
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
 
najhCommented:
are you using Flash CS3?

I wonder if _level0 might work in place of _root...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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
 
pdbenAuthor Commented:
Thanks, that did the trick!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now