A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: javascript help

  1. #1
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438

    javascript help

    Hi,

    I need to send a variable from a javascript function to a flash movie embedded in the same HTML page. I downloaded a demo from Macromedia, but it sends the variable from a textfield, either onChange or onSubmit. How can I adapt this to send the variable when the page loads?...
    code:

    <HTML>
    <HEAD>
    <TITLE>javascript_to_flash</TITLE>
    </HEAD>
    <SCRIPT LANGUAGE=JavaScript>
    <!--
    function doPassVar(args){
    var myLoad = "imageList2.txt";
    window.document.myFlash.SetVariable("myVar", myLoad);
    }
    //-->
    </SCRIPT>
    <BODY bgcolor="#FFFFFF">
    //attempt to send the variable when the HTML page loads
    <window.document.onLoad=window.document.myFlash.Se tVariable("myVar", myLoad)>
    //the form field below correctly sends the variable
    <form name="form1" onLoad="doPassVar(myLoad);" action="#">
    <input type="text" name="myLoad" maxlength="45" onChange="doPassVar(this);">
    </form>
    <p><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"
    width=400 height=180 id="myFlash">
    <param name=movie value="javascript_to_flash.swf">
    <param name=quality value=high>

    <embed src="javascript_to_flash.swf" quality=high width=400 height=180 type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" name="myFlash" swLiveConnect="true">
    </embed>
    </object></p>
    </BODY>
    </HTML>




    Thanks in advance for any suggestions
    NTD

  2. #2
    Senior Member
    Join Date
    Feb 2001
    Location
    On the fifth floor.
    Posts
    1,202
    If I understand your question correctly (How can I adapt this to send the variable when the page loads?...), then...
    <BODY bgcolor="#FFFFFF" onLoad="doPassVar(this)">
    If you try something different - take a look at the attached example
    Attached Files Attached Files

  3. #3
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    Thanks,

    That is what I needed. For some reason, I had it in my head that it needed to be....

    <window.document.onLoad="doPassVar(myLoad)">

    Thanks again
    Regards
    NTD

  4. #4
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    is there any need for javascript? if you're just passing in a variable when the page loads could it be done using flashvars instead (which should be more reliable across different browsers - eg it won't fail if javascript is turned off)

    with the other param tags add,

    <param name="flashvars" value="myVar=imageList2.txt">

    and in the embed tag add an extra attribute,

    flashvars="myVar=imageList2.txt"

  5. #5
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    Hi,

    I have only recently looked into this. The main movie loads an imageList text file containing image names. It was requested to be able to change which imageList text file is to be used when embedding the .swf into the html page. So, for example, you could have the same movie embedded in 3 different places, each using a different text file with the images to be used.I finally got this working with javascript passing the variable to the flash movie thanks to sergwiz post. However, I have read about some possible browser issues with this method and, like you say,.... someone turning off javascript in thier browser. I looked into your suggestion, but I can't seem to get it to work...... been one of those days when nothing seems to work for me. Here is what I have tried.......

    code:

    <HTML>
    <HEAD>
    <meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
    <TITLE>imageView</TITLE>
    </HEAD>
    <BODY bgcolor="#FFFFFF">
    <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
    ID="imageView" WIDTH="500" HEIGHT="150" ALIGN="">
    <PARAM NAME=movie VALUE="imageView.swf">
    <PARAM NAME=menu VALUE=false>
    <PARAM NAME=quality VALUE=high>
    <PARAM NAME=bgcolor VALUE=#CCCCCC>
    <PARAM NAME="flashvars" VALUE="myLoad=imageList.txt">
    <EMBED src="imageView.swf" menu=false quality=high bgcolor=#CCCCCC WIDTH="500" HEIGHT="150" swLiveConnect=true ID="imageView" NAME="imageView" ALIGN="" flashvars="myLoad=imageList.txt"
    TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>
    </OBJECT>
    </BODY>
    </HTML>



    Would I need swLiveConnect when passing a parameter? See any formatting errors?

    Thanks for looking
    NTD

  6. #6
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hi,

    You wouldn't need swliveconnect if you're using flashvars. other than that your code looks ok - so it *should* be creating the variable myLoad on the main timeline of your movie.

    what happens if you add the following to frame 1,

    getURL("javascript:alert('" + myLoad + "');void(0);");

    ?

  7. #7
    Banned NTD's Avatar
    Join Date
    Feb 2004
    Posts
    3,438
    Hi,

    After some playing around, I finally figured out I was handling the variable incorrectly in the Flash movie. I now have it working for the Javascript method and passing the variable as a parameter.

    Thanks for the very helpful suggestions.

    Regards
    NTD

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center