Solved

passing variables in to flash using case statements

Posted on 2003-12-04
7
504 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

828 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