dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: passing variables via javascript to flash

  1. #1
    Junior Member
    Join Date
    Jul 2000
    Posts
    27
    I'm making a flash piece that let's the user select song titles and then pops open a window that contains info about the song as well as plays the song. I've made a menu in flash that via javascript opens up a specially sized window with one flash piece. The idea is to pass the flash piece a variable (the selection from the menu) so that it knows what xml doc and mp3 to load in. So, to open the window, I have used this code: getURL ("javascript:void(window.open('mp3.html','MyWindow Name','resizable=no,height=400,width=550,top=0,lef t=0,right=0,bottom=0'))");
    I've also written this code: variable = this.text; which lets me know which song was selected. So, how do I pass this variable to the html page so that the flash piece embedded in that page sees the variable and acts accordingly? Thanks in advance.

    Johnny

  2. #2
    Member
    Join Date
    Jan 2002
    Posts
    50
    first check here on affect Flash with Javascript:
    http://www.flashkit.com/tutorials/In...77/index.shtml

    now what you may want to do is create a javascript function in the html file like:

    function OpenChild(someStr){
    childWindow = window.open('mp3.html','MyWindowName','resizable=n o,height=400,width=550,top=0,left=0,right=0,bottom =0'))");
    // here you want do do some code to check to see if the window has already been loaded(i dont remember this code off the top of my head

    // then if your flash movie is formatted like it says to in the above tutorial, you can do the following

    window.document.childWindow.FlashMovie.SetVariable ("someStr", flashStr);
    //where FlashMovie is the OBJECT ID set in the html file of the child window

    }

    so instead in your flash file you can simply make a call to getURL("JavaScript:OpenChild("+str+");"

  3. #3
    Member
    Join Date
    Jan 2002
    Posts
    50
    actually its more of a matter of having that flash movie loaded in time, than having the childWindow load in time before you do the SetVariable.

    to ensure that, i _think_ you can do this.

    in the parent window, you can create a global variable and another function:

    var loaded = null;

    function ChildMovieIsLoaded(){
    loaded = true;
    }

    so within your child flash movie you can have a call to getURL("JavaScript:ChildMovieIsLoaded()", _parent); when the movie has been loaded of course...

    and then in your OpenChild function after you do a window.open(), you can do:
    for(i=0; i < 1000000 || loaded != null; i++){}
    if(loaded == null){
    alert("Child Movie not fully loaded in time");
    }

    and do an evil little polling loop(which shouldnt be too bad if your movie doesnt take too long to load.

  4. #4
    Junior Member
    Join Date
    Jul 2000
    Posts
    27
    Thanks for your help. I'm swamped right now, so I haven't actually gotten to try what you suggested. But, I do appreciate your help. Thanks.

    Johnny

    Originally posted by ironmang
    actually its more of a matter of having that flash movie loaded in time, than having the childWindow load in time before you do the SetVariable.

    to ensure that, i _think_ you can do this.

    in the parent window, you can create a global variable and another function:

    var loaded = null;

    function ChildMovieIsLoaded(){
    loaded = true;
    }

    so within your child flash movie you can have a call to getURL("JavaScript:ChildMovieIsLoaded()", _parent); when the movie has been loaded of course...

    and then in your OpenChild function after you do a window.open(), you can do:
    for(i=0; i < 1000000 || loaded != null; i++){}
    if(loaded == null){
    alert("Child Movie not fully loaded in time");
    }

    and do an evil little polling loop(which shouldnt be too bad if your movie doesnt take too long to load.

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