JavaScript Control of your Swish SWF
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: JavaScript Control of your Swish SWF

  1. #1
    Senior Member
    Join Date
    Jul 2000
    Posts
    350
    Whilst we wait with anticipation to Swish V2 with it's FS Command capability, I thought I should remind everyone of the power of JavaScript with SWF's.

    You can easily PLAY / STOP, Check movie loaded, ZOOM, jump frames and so on with a bit of scripting.
    This allows you to communicate with your movies from your web page and control a movie outside of itself.
    For example, simple text of GIF buttons elsewhere on the page could give reactions to your movie.
    I find these features underused, there is a lot of potential in these features if you stop and think of what you can do.

    An example of these features being used on site is at http://www.williamorbit.com, when in the site, when you press a navigation button (left side), it changes the SWF frame in the movie top-left of the site - I use many others in a more complicated way elsewhere.

    A quick list of JS commands with SWF are as follows:

    Play() - Start playing the animation.
    StopPlay() - Stop playing the animation.
    IsPlaying() - Returns true if the movie is currently playing.
    GotoFrame (int frameNum) - Goto a specific frame of the movie. (i.e. GotoFrame(200) )
    TotalFrames() - Returns the total number of frames in the movie.
    Rewind() - Go to the first frame.
    SetZoomRect (int left, int top, int right, int bottom) - Zoom in on a rectangular area of the movie.
    Zoom(int percent) - Zoom the view by a relative scale factor. (i.e. Zoom(50) for 50%)
    Pan (int x, int y, int mode) - Pan a zoomed in movie. The mode can be: 0 = pixels, 1 = % of window.
    PercentLoaded() - Returns the percent of the .swf file that has streamed in to the browser so far ranges (0-100).

    In this example below, assume the SWF stops at frame 10 because you've told it to in SWISH.
    But the JavaScript function below will cause the movie to move into frame 25 when the function is called either by an action/mouseover etc etc.

    Example:
    // the JavaScript Stuff (have this in the <head> section of your HTML)

    <html><head>
    <script Language="JavaScript">
    <!--
    function Jump(){
    if (document.MySWF.PercentLoaded() == 100){
    document.MySWF.GotoFrame(25)
    document.MySWF.Play()
    }
    }
    //-->
    </script>
    </head>
    <BODY BGCOLOR="#ffffff" TEXT="#000000" marginheight=0 marginwidth=0 topmargin=0 leftmargin=0 rightmargin=0 id=all>

    // In your your EMBED and OBJECT tags, add ID="MySWF" (see below)

    <OBJECT CLASSID="clsid27CDB6E-AE6D-11cf-96B8-444553540000"
    ID="MySWF"
    WIDTH=100 HEIGHT=100
    CODEBASE="http://active.macromedia.com/flash2/cabs/swflash.cab#version=2,0,0,11">
    <PARAM NAME="Movie" VALUE="my.swf">
    <EMBED NAME="MySWF"
    MAYSCRIPT SRC="my.swf"
    WIDTH=100 HEIGHT=100
    PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
    </OBJECT>

    <a href="JavaScript:Jump();">Click here to jump to frame 25</a>

    </body>
    </html>



    Please don't ask me any more questions right now, have a play with it yourself ... it's the best way to learn!

    For more information see http://www.macromedia.com/support/fl...ts/tn4160.html

    regards,
    Richard Shea.

  2. #2
    Junior Member
    Join Date
    Nov 2000
    Posts
    29
    Thank you for the tips Richard. They will be put to good use.

    Also, I must compliment you on an excellent piece of work for the Orbit site. Lots of neat, well designed but functional features. {I like how you have added the extra navbar to ie5- How do they do that :-) }

    William Orbit is a talented individual who's work is complimented by a superb web site. Well done.

  3. #3
    Registered User
    Join Date
    Jul 2013
    Posts
    1
    Thank you very much for thsi nice post.

    Please help me out that how can I Zoomout the SWF using javascript ?? please put an example!!!

    thanks in advance

  4. #4
    Carpe Diem - Moderator wolfgross's Avatar
    Join Date
    Apr 2001
    Location
    SWiSHzone
    Posts
    1,700
    suman685 - this topic is 13 years old - try one of the JavaScript forums.

    wolf

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

Poll by Flashkit.com