8 Replies - 25360 Views - Last Post: 16 January 2004 - 12:41 AM

#1 pioSko  Icon User is offline

  • still.dreaming
  • member icon

Reputation: 23
  • View blog
  • Posts: 1,888
  • Joined: 06-June 03

Loading Javascript Variables Into Flash

Posted 13 January 2004 - 12:04 PM

Is it possible to load Javascript variables into flash?

Example: I have manu where you select either 1, 2 or 3. The choice is moved to the next page via the link (ie. www.something.com/main.htm?variable=3)

in the next page I have a Javascript like this to seperate the 3 from the rest:

Quote

<script language="Javascript">
var str = String(document.location)
function myFunction() {
document.something.value = str.substr(str.length-1,1);
}
//-->
</script>
</head>


OK, so now can I get a flash file ON that page to read that variable?

Is there a different way that I don't know of?


I've searched the net for help (and have found and learned a lot) but my time is running out and this is the final step that I need. If I can get flash to read that variable (or find a different way of pasing a variable from page to page(w/ flash) then I'll be a happy chappy.

Cheers,

Is This A Good Question/Topic? 0
  • +

Replies To: Loading Javascript Variables Into Flash

#2 cyberscribe  Icon User is offline

  • humble.genius
  • member icon

Reputation: 10
  • View blog
  • Posts: 1,062
  • Joined: 05-May 02

Re: Loading Javascript Variables Into Flash

Posted 14 January 2004 - 12:23 AM

Red|5, on Jan 13 2004, 12:04 PM, said:

Is there a different way that I don't know of?

What comes to mind is to use Javascript's ability to print out html:

<object ... flash ... blah blah>
<param name='...' value='...'>

<script langauge="javascript">
print "<param name='myvariable' value='myvalue'>";
</script>

...
</object>



then just nab your parameter by name inside your action script.
Was This Post Helpful? 0
  • +
  • -

#3 pioSko  Icon User is offline

  • still.dreaming
  • member icon

Reputation: 23
  • View blog
  • Posts: 1,888
  • Joined: 06-June 03

Re: Loading Javascript Variables Into Flash

Posted 14 January 2004 - 01:51 AM

Found this, too.
Was This Post Helpful? 0
  • +
  • -

#4 pioSko  Icon User is offline

  • still.dreaming
  • member icon

Reputation: 23
  • View blog
  • Posts: 1,888
  • Joined: 06-June 03

Re: Loading Javascript Variables Into Flash

Posted 14 January 2004 - 04:40 AM

ok, new problem:

<script language="Javascript">

var lang = String(document.location);
lang = lang.substr(lang.length-1,1);


//-->
</script>


<object classid="bleh" 
codebase="bleh>

    document.write('<param name=movie value="main.swf?lang='+lang+'">');
    <param name=quality value=high>
    <embed src="main.swf" quality=high

</embed> 
</object>


First code get's the location of the html file and throws away everything except the last character (my variable value).

Second code embeds flash and I want it to identify it as main.swf?lang=3... (3 being the value of the variable lang).

However, flash reads it only as http://www.......com/main.swf?lang='+lang+' and!! .. it does (in flash) give lang a value but as this:

' lang '

I've played around with the quotation marks and taken example from other sites use of this method. What am I doing wrong? :(

cheers,

This post has been edited by Red|5: 14 January 2004 - 05:01 AM

Was This Post Helpful? 0
  • +
  • -

#5 pioSko  Icon User is offline

  • still.dreaming
  • member icon

Reputation: 23
  • View blog
  • Posts: 1,888
  • Joined: 06-June 03

Re: Loading Javascript Variables Into Flash

Posted 14 January 2004 - 07:46 AM

update:

OK, i have found now that you can send vars to flash via:

<param name="FlashVars" value="lang=3">

This way I can take the value of lang within flash. However...

document.write('<param name="FlashVars" value="lang='+lang+'">');

... gives lang the value of ' lang ' . Why doesn't it read the value of the variable and substitute it??


Oh, and is it possible to dynamically build an object/embed tag structure? Put it in a function and execute it in a table?
Was This Post Helpful? 0
  • +
  • -

#6 cyberscribe  Icon User is offline

  • humble.genius
  • member icon

Reputation: 10
  • View blog
  • Posts: 1,062
  • Joined: 05-May 02

Re: Loading Javascript Variables Into Flash

Posted 14 January 2004 - 09:46 PM

Red|5, on Jan 14 2004, 07:46 AM, said:

document.write('<param name="FlashVars" value="lang='+lang+'">');

... gives lang the value of ' lang ' . Why doesn't it read the value of the variable and substitute it??

Try this:

document.write("<param name=\"FlashVars\" value=\"lang="+lang+"\">");

or this:

document.write("<param name=\"FlashVars\" value=\"lang="+lang.toString()+"\">");

Quote

Oh, and is it possible to dynamically build an object/embed tag structure? Put it in a function and execute it in a table?


You mean in PHP? Sure.
Was This Post Helpful? 0
  • +
  • -

#7 pioSko  Icon User is offline

  • still.dreaming
  • member icon

Reputation: 23
  • View blog
  • Posts: 1,888
  • Joined: 06-June 03

Re: Loading Javascript Variables Into Flash

Posted 15 January 2004 - 01:03 AM

Nope. Didn't work.

I know the variable is defined because I tested that. Did alert(lang); and I got positive results through out the document.

One thing that is puzzling me is that when I poen this .html in say dreamweaver or other program that identifies code elements by colour, it sees this line like so:

document.write('<param name="FlashVars" value="lang='+lang+'">');

but if I move this line between the <script> tag in the <head> section, it looks like this:

document.write('<param name="FlashVars" value="lang='+lang+'">');


In the <object> tag, the quote marks aren't recognised.

That's why I asked about dynamicaly creating the <object> tag. I will know today if the client's host supports PHP.
Can it be done with Javascript?

(EDIT: NO PHP support, damn it. Have to use Javascript, or find a different way :( )

This post has been edited by Red|5: 15 January 2004 - 06:57 AM

Was This Post Helpful? 0
  • +
  • -

#8 Cookie Mobster  Icon User is offline

  • nooneenooneenooonee
  • member icon

Reputation: 7
  • View blog
  • Posts: 4,730
  • Joined: 12-October 01

Re: Loading Javascript Variables Into Flash

Posted 15 January 2004 - 01:00 PM

Macromedia Knows All Flash Solutions:

http://www.macromedi....htm#javascript

Basicly with IE and Netscape (sorrry no Mozillia or Opera) you can directly pass to a flash movie from a javascript funtion. very easy to do and it looks kinda cool.
Was This Post Helpful? 0
  • +
  • -

#9 pioSko  Icon User is offline

  • still.dreaming
  • member icon

Reputation: 23
  • View blog
  • Posts: 1,888
  • Joined: 06-June 03

Re: Loading Javascript Variables Into Flash

Posted 16 January 2004 - 12:41 AM

Time ran out. Had to use Plan B.

I created 3 HTML files (main1.htm, main2.htm and main3.htm). In each, the value of the "FlashVars" being passed on varies corresponding with the language I want.

Example:
...
<param name="movie" value="main.swf?lang=3">
<param name="FlashVars" value="lang=3">
<embed src="main.swf?lang=3" quality="high" ... 




This passes the value of lang to IE, Netscape AND Opera and Firebird :D

You can check it out in here. Don't critique the design as I don't like it myself :P

Thanks for the help anyway, guys.

This post has been edited by Red|5: 16 January 2004 - 12:43 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1