A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 31

Thread: JavaScript Question

  1. #1
    Is there a way to have JavaScript tell a Flash movie to go to a specific frame when a page loads. I would like to use the same movie on different pages, so that the movie can have smoother transitions from one html page to the next, and so that a new movie doesn't have to load. I do not want to use frames.

    Any help is greatly appreciated.

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Posts
    1,317
    Hi,

    <script>
    function done(){
    var movie = window.document.movie;
    movie.GotoFrame(frameNumber);
    }
    // be sure to inclue id=movie in the <object> tag and
    // name=movie swLiveConnect="true" in the <embed> tag.
    </script>

    <body onLoad="done()">

  3. #3
    Thanks, this is EXACTLY what I needed.

    Have a great weekend!

  4. #4
    Do you know if I can have the JS tell the movie to go to a specific scene? If so, how?

    Originally posted by edeveloper
    Hi,

    <script>
    function done(){
    var movie = window.document.movie;
    movie.GotoFrame(frameNumber);
    }
    // be sure to inclue id=movie in the <object> tag and
    // name=movie swLiveConnect="true" in the <embed> tag.
    </script>

    <body onLoad="done()">

  5. #5
    Senior Member
    Join Date
    Aug 2000
    Posts
    1,317
    Hi,
    I was looking at MM but could find anything on target a scene but what you could do is use the GotoFrame the way it is but in the frame tell flash to go to the scene you want.
    hope this helps.

  6. #6
    Your the man!!!

    Thanks

  7. #7
    Junior Member
    Join Date
    Mar 2001
    Posts
    19

    Angry

    Ok, I have a really stupid question, but I'm allowed to ask since I'm a novice. I have an SWF called "index.swf" that I have placed in my HTML document called "main.html". I want "index.swf" to jump to frame 265. This is the script you wrote:

    <script>
    function done(){
    var movie = window.document.movie;
    movie.GotoFrame(frameNumber);
    }
    // be sure to inclue id=movie in the <object> tag and
    // name=movie swLiveConnect="true" in the <embed> tag.
    </script>

    So should the script in my html look like this:

    <script language="JavaScript1.2">
    function done(){
    var movie = self."main.swf"."index.swf";
    movie.GotoFrame(265);

    </script>

    <body onLoad="done()">

    And should my object and embed tags contain this:
    id="index.swf" in the <object> tag and
    name="index.swf" swLiveConnect="true" in the <embed> tag?

    I'd really appreciate your help. Thanks.

    Nick
    __________________

  8. #8
    Senior Member
    Join Date
    Aug 2000
    Posts
    1,317
    Hi,
    Everything looks good except where you call the flash object in the javascript:
    var movie = self."main.swf"."index.swf";
    should be
    var movie = window.document.main;
    and don't forget the closing brace - }
    and in the object tag: id=movie
    and in the embed tag: name=movie swLiveConnect="true"

  9. #9
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    what happens if the movie has not yet loaded frame 265 when the html onload fires?
    Or were you talking about onunload() ?

    Musicman

  10. #10
    Senior Member
    Join Date
    Aug 2000
    Posts
    1,317
    picky picky picky

    <script>
    function done(){
    var movie = window.document.movie;
    movie.GotoFrame(frameNumber);
    }

    function chkIt(){
    var movie = window.document.movie;
    // TGetPropertyNum says to get the property by the number value.
    // FRAMESLOADED is 12
    var frameCount = movie.TGetPropertyNum('/',12)
    if(frameCount == frameNumber)
    done()
    }
    // be sure to inclue id=movie in the <object> tag and
    // name=movie swLiveConnect="true" in the <embed> tag.
    </script>
    <TITLE>loaded</TITLE>
    </HEAD>
    <BODY bgcolor="#FFFFFF" onLoad="chkIt()">

  11. #11
    Junior Member
    Join Date
    Mar 2001
    Posts
    19

    Doh!

    I still can't get this to work. You're probably sick of me pestering about this question and you probably don't want to read this but this is my html:

    <HTML>
    <HEAD>
    <TITLE>JQ Main Page</TITLE>
    <SCRIPT LANGUAGE="JavaScript1.2">
    function done(){
    var movie = window.document.movie;
    movie.GotoFrame(265);
    }

    function chkIt(){
    var movie = window.document.movie;
    var frameCount = movie.TGetPropertyNum('/',12)
    if(frameCount == frameNumber)
    done()
    }

    </script>
    </HEAD>

    <BODY
    bgcolor="#FFFFFF"
    onLoad="chkIt();"
    leftmargin="0"
    topmargin="0"
    marginwidth="0"
    marginheight="0">
    <CENTER>

    <OBJECT classid="clsid27CDB6E-AE6D-11cf-96B8-444553540000"
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"
    WIDTH="100%"
    HEIGHT="100%">

    <PARAM NAME="movie">
    <PARAM id="movie">
    <EMBED src="index.swf" name="movie" swLiveConnect="true" quality="high" bgcolor="#FFFFFF" WIDTH="100%" HEIGHT="100%" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
    </EMBED>

    </OBJECT>
    </CENTER>
    </BODY>
    </HTML>

    What am I doing wrong that would keep the Jscript from causing index.swf to jump to frame 265?

  12. #12
    Senior Member
    Join Date
    Aug 2000
    Posts
    1,317
    No Problem!
    instead of a new param tag add the "id" part to the object tag:
    <OBJECT classid="clsid27CDB6E-AE6D-11cf-96B8-444553540000"
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" WIDTH="100%" HEIGHT="100%" id=movie>
    also, make sure that (frameCount == frameNumber) is a number.
    that should do it. if you still have issues, you can send me the files and i will look at your code if you like.

    [Edited by edeveloper on 06-15-2001 at 04:58 PM]

  13. #13
    Member
    Join Date
    Jun 2001
    Location
    Bay Area, California
    Posts
    39
    Hi there!

    I also am a complete novice with Flash (my first post!) and JavaScripting, and I am having trouble determining where you are using the term 'movie' as a variable, and where you intend for the word 'movie' to be used literally.

    In one instance above, 'main' is substituted for 'movie', and in another it is not....

    I suppose I should mention, I am trying to make this work on a Macintosh, if that makes a difference...

    I have been struggling with this off and on for days now, any help would be GREATLY appreciated.

    Thanks!

  14. #14
    Junior Member
    Join Date
    Mar 2001
    Posts
    19

    Pitir

    The term 'movie' apparently is a variable, not the name of an swf. I too thought it was a placeholder for the name of my swf which is why you saw it replaced with "main.swf". Edevelover helped me out though. Unfortunately however i still cannot get this script to do what i want it to. I've got another question going in this forum right now called "Have you ever had this happen to you?" where I'm discussing trying to overcome this navigation problem using another swf to tell index.swf to jump to the correct frame. Once again I'm failing at my task as I cannot get that method to work either. Anyway, just keep checkin' in and I'm sure someone will crack the problem. And let me know if it's you.

    Nick

  15. #15
    Member
    Join Date
    Jun 2001
    Location
    Bay Area, California
    Posts
    39
    Nick

    Thanks for your reply, I have been trying that other techniqe, too - no luck so far. I'm guessing getting an .swf file to go to a frame in another .swf file is the way to go, but can't find any reference to it.

  16. #16
    Senior Member
    Join Date
    Aug 2000
    Posts
    1,317
    Hey Nick,

    OK. You are really close to getting this .
    first:
    if(frameCount == frameNumber)
    should be
    if(frameCount == 265 ) //the frame number you want to call
    second:
    you don't need
    <PARAM id="movie">
    you do need
    <OBJECT classid="clsid27CDB6E-AE6D-11cf-96B8-444553540000"
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" WIDTH="100%" HEIGHT="100%" id=movie>
    and i think that is it .

    Pitir:
    bad news. passing vars with flash and internet explorer versions less that 5 and the latest flash plugin won't work. sorry. 5 with the latest plugin will work fine though and will work fine with all versions of ns back to 4.51(i think).
    good luck.



  17. #17
    Junior Member
    Join Date
    Mar 2001
    Posts
    19

    Smile Hmmmmmmm

    Well, I'm still not getting it to work. It's a little different than before since I've been trying to get various things to work but this is what I've got:

    <html>

    <head>
    <meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
    <meta name="generator" content="Adobe GoLive 4">
    <title>Jaster-Quintanilla Consulting Engineers</title>
    <script language="JavaScript">
    function done(){
    var movie = window.document.movie;
    movie.GotoFrame(265);
    }

    function chkIt(){
    var movie = window.document.movie;
    var frameCount = movie.TGetPropertyNum('/',12)
    if(frameCount == 265)
    done()
    }
    </script>
    </head>

    <body bgcolor="white" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="chkIt()">
    <center>
    <OBJECT classid="clsid27CDB6E-AE6D-11cf-96B8-444553540000"
    codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"
    WIDTH="100%"
    HEIGHT="100%" id=movie>
    <embed src="index.swf" width="100%" height="100%" name=movie swLiveConnect="true"></embed></object></center>
    </body>

    </html>


  18. #18
    Member
    Join Date
    Jun 2001
    Location
    Bay Area, California
    Posts
    39
    Yup, that looks identical to my code - and it doesn't work for me either.

    I'm using IE 5 and Netscape 4.77.

    hmmmmm.......


  19. #19
    Senior Member
    Join Date
    Aug 2000
    Posts
    1,317
    hey guys,
    give me a few and i will put a zip together with the fla,swf and html and post it for downloading.

  20. #20
    Junior Member
    Join Date
    Mar 2001
    Posts
    19

    Smile Alrighty then

    Cool! You rock!

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