开发者

Why is my actionscript looping?

I'm new to the whole Action Script / Flash world...but trying to teach myself enough to get something done.

I'm sure the answer to this is simple...but I have a .as file with the following code in it:

package
{
    import flash.external.ExternalInterface;

    public class Sender
    {
        public function Sender()
        {
            ExternalInterface.call("func1()");
        }
    }
}

I've got a fla with the following code (I've touched nothing else):

import Sender;

var mySender:Sender = new Sender();

Now after publishing, I made some tweaks to the html file (included below)....and my Javascript gets called (yay!). Unfortunately, after dismissing the alert, it gets called again...and again.......and again. I have no clue why (I have verified that my flash movie isn't set to loop, but that's all I have). Any help would be greatly appreciated!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <title>sender</title>
        <meta http-equiv="Content-Type" content="te开发者_运维百科xt/html; charset=utf-8" />
        <style type="text/css" media="screen">
        html, body { height:100%; background-color: #ffffff;}
        body { margin:0; padding:0; overflow:hidden; }
        #flashContent { width:100%; height:100%; }
        </style>

        <script>
            function func1()
            {
                alert('hello external stuff');
            }
        </script>
    </head>
    <body>
        <div id="flashContent">
            <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="1" height="1" id="sender" align="middle">
                <param name="movie" value="sender.swf" />
                <param name="quality" value="high" />
                <param name="bgcolor" value="#ffffff" />
                <param name="play" value="true" />
                <param name="loop" value="true" />
                <param name="wmode" value="window" />
                <param name="scale" value="showall" />
                <param name="menu" value="true" />
                <param name="devicefont" value="false" />
                <param name="salign" value="" />
                <param name="allowScriptAccess" value="always" />
                <!--[if !IE]>-->
                <object type="application/x-shockwave-flash" data="sender.swf" width="1" height="1">
                    <param name="movie" value="sender.swf" />
                    <param name="quality" value="high" />
                    <param name="bgcolor" value="#ffffff" />
                    <param name="play" value="true" />

                    <param name="loop" value="true" />
                    <param name="wmode" value="window" />
                    <param name="scale" value="showall" />
                    <param name="menu" value="true" />
                    <param name="devicefont" value="false" />
                    <param name="salign" value="" />
                    <param name="allowScriptAccess" value="always" />
                <!--<![endif]-->
                    <a href="http://www.adobe.com/go/getflash">
                        <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
                    </a>
                <!--[if !IE]>-->
                </object>
                <!--<![endif]-->
            </object>
        </div>
    </body>
</html>


In the html code you posted, it says

<param name="loop" value="true" />

It is possible that this is the cause.

EDIT: Maybe you only checked in the IDE if the .swf file exported was to loop, but the html generated by CS5 put in the tag regardless.

EDIT2: I agree with gmale that you should put stop(); in your code. If you put your code anywhere else (or if you want someone else to use it) they might have loop set to true, in which case coding it to be foolproof is your only way to ensure that it doesn't loop. This principle applies to all AS3 code.


Also, try putting the following code in your very first frame:

stop();

if you have an animation, put it in your last frame. By default, the flash player loops your SWF files. You can change that behavior by setting properties in the publish settings (as mentioned by 31eee384, that will set looping to false). You can set that property by clicking File > Publish Settings..., then going to the HTML tab and unchecking the box that says "Loop" (it may be a little different on windows but you get the idea):

Why is my actionscript looping?

Or you can write your code in a way that controls the movie (by placing stop() where you need it). I prefer that option so that regardless of whether looping is set in the HTML, my application/animation still works as I intend.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜