Solved

passing variables in to flash using case statements

Posted on 2003-12-04
7
510 Views
Last Modified: 2008-03-10
Does any one know how to pass a variable into flash from a html file using javascript cases.  e.g:

I am trying to use:

<SCRIPT FOR="MediaPlayer"
        EVENT="ScriptCommand(sType, sParam)"
        LANGUAGE="JScript">
 switch (sParam)
    {
    case "Slide1":
       //variable i am trying to pass 'name = XXX' where slides is the id/name of the flash file.
       break;

    case "Slide2":
       //variable i am trying to pass 'name = YYY' where slides is the id/name of the flash file.
       break;       
                   
    }
</SCRIPT>


so as each different case statement is matched a different value for the variable is passed.

Does any one know the script i can use to do this?  I need an example.

Thanx
0
Comment
Question by:Jyontex
  • 4
  • 3
7 Comments
 
LVL 27

Accepted Solution

by:
negatyve earned 100 total points
ID: 9877570
<SCRIPT FOR="MediaPlayer"
        EVENT="ScriptCommand(sType, sParam)"
        LANGUAGE="JScript">
switch (sParam)
{
      case "Slide1":
            var myvariable = "hello"
            break;
      case "Slide2":
            var myvariable = "byebye"
            break;      
}
var IE = navigator.appName.indexOf("Microsoft") != -1;
var targetMovie = IE ? window.slides : window.document.slides;
targetMovie.SetVariable("variable_name", myvariable);
</SCRIPT>
0
 

Author Comment

by:Jyontex
ID: 9881303
Hi this looks like the kind of thing i want but still cannt get it to work.

i am using:

<HEAD>
<TITLE>Test</TITLE>

</HEAD>
<BODY bgColor=#FFFFFF text=#ffffff>
<SCRIPT FOR="MediaPlayer" EVENT="MarkerHit(lMarkerNum)" LANGUAGE="JScript">
{
      MediaPlayer.Play();
}
</SCRIPT>
<SCRIPT FOR="MediaPlayer"
        EVENT="ScriptCommand(sType, sParam)"
        LANGUAGE="JScript">
 switch (sParam)
    {
    case "Slide1":
       var frameName = "a1"
       break;

    case "Slide2":
       var frameName = "b1"
       break;

    case "Slide3":
       var frameName = "c1"
       break;

var IE = navigator.appName.indexOf("Microsoft") != -1;
var targetMovie = IE ? window.Slides : window.document.Slides;
targetMovie.SetVariable("frameName", frameName);       
                   
    }
</SCRIPT>
<table width="800" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><OBJECT ID="MediaPlayer" WIDTH=320 HEIGHT=240
    CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95"
    STANDBY="Loading Windows Media Player components..."
    TYPE="application/x-oleobject" align="middle" vspace="0">
        <PARAM NAME="FileName" VALUE="test.wmv">
        <PARAM NAME="ShowControls" VALUE=true>
        <PARAM NAME="DisplaySize" VALUE=0>
        <PARAM NAME="AutoStart" VALUE=true>
        <EMBED TYPE="application/x-mplayer2"
    SRC="test.wmv"
    WIDTH=320
    HEIGHT=240 align="middle" vspace="0"> </EMBED> </OBJECT></td>
  </tr>
  <tr>
    <td><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0" width="80" height="20" align="top" id="Slides">
        <param name=movie value="test.swf">
        <param name=quality value=high>
        <embed src="test.swf" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" align="top">
        </embed> </object></td>
  </tr>
</table>
</BODY>
</HTML>

and a simple dynamic text box in the flash to display the value passed in the parameter.

Can you see where i'm going wrong?
0
 
LVL 27

Expert Comment

by:negatyve
ID: 9881473
What does this script do?

<SCRIPT FOR="MediaPlayer"
        EVENT="ScriptCommand(sType, sParam)"
        LANGUAGE="JScript">
0
Independent Software Vendors: 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!

 

Author Comment

by:Jyontex
ID: 9881599
its picking up variables passed from the wmv and passing it to the switch statement.  (that works), so you can ignore that bit.  Only having problems passing new variables to the flash fom there.
0
 
LVL 27

Expert Comment

by:negatyve
ID: 9881812
Before I make any test, if you try:

switch (sParam)
{
      case "Slide1":
            var frameName = "a1"
            break;

      case "Slide2":
            var frameName = "b1"
            break;

      case "Slide3":
            var frameName = "c1"
            break;
}
alert(frameName)

what happens?
0
 

Author Comment

by:Jyontex
ID: 9881890
it doesnt work.  the alert needs to be within the case.

and your script works if i use:

<SCRIPT FOR="MediaPlayer"
        EVENT="ScriptCommand(sType, sParam)"
        LANGUAGE="JScript">
 switch (sParam)
    {
    case "Slide1":
       var frameName = "a1"
var IE = navigator.appName.indexOf("Microsoft") != -1;
var targetMovie = IE ? window.Slides : window.document.Slides;
targetMovie.SetVariable("frameName", frameName);
       break;

    case "Slide2":
       var frameName = "b1"
var IE = navigator.appName.indexOf("Microsoft") != -1;
var targetMovie = IE ? window.Slides : window.document.Slides;
targetMovie.SetVariable("frameName", frameName);
       break;

    case "Slide3":
       var frameName = "c1"
var IE = navigator.appName.indexOf("Microsoft") != -1;
var targetMovie = IE ? window.Slides : window.document.Slides;
targetMovie.SetVariable("frameName", frameName);
       break;
             
    }
</SCRIPT>

can this be simplified?
0
 

Author Comment

by:Jyontex
ID: 9881900
Its ok....i put the script into a simple function.

Thanx for your help
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question