动作:添加相同的swf文件的多个实例的阶段多个、实例、阶段、动作

2023-09-08 15:21:42 作者:懂事了

我在ActionScript 3.0使用FlashPunk游戏引擎和SDK的FlashDevelop创建游戏。 我已经创建了自己的MovieClip类,它接受一个preloaded短片文件。

I'm creating a game in ActionScript 3.0 using the FlashPunk game engine and the FlashDevelop SDK. I've created my own MovieClip class that takes a preloaded movie clip file.

public function MyMovieClip(file:MovieClip, posX:int, posY:int, frameRate:int) 
    {
        movieClip = file;
        movieClip.x = posX;
        movieClip.y = posY;
        movieClip.stop();
        FP.stage.addChild(movieClip);


        timer = new Timer((1 / frameRate) * 1000);
        timer.start();
        timer.addEventListener(TimerEvent.TIMER, onTick);
    }

我的影片剪辑的更新如下:

The update for my movie clip is as follows:

private function onTick(e:TimerEvent):void
    {
        if (isRepeating)
        {
            if (movieClip.currentFrame == movieClip.totalFrames )
            {
                movieClip.gotoAndStop(0);
            }
        }
        movieClip.nextFrame();
    }

这是我遇到的问题是,当我有MyMovieClip类使用相同的SWF文件的多个实例,只有最后一个实例呈现和我有这个类的每个实例进行更新。(如3个实例MyMovieClip的,最后一个实例是在速度3倍的更新。)

The problem that I'm having is that when I have multiple instances of the MyMovieClip class using the same swf file, only the last instance is rendered and is updated for each instance of the class that I have.(e.g 3 instances of MyMovieClip, the last instance is updates at 3 times the speed.)

如果再信息是必要的,我会很乐意提供它。

If anymore info is needed I'll be happy to supply it.

推荐答案

您可以通过执行此创建相同加载的SWF的新实例:

You can create a new instance of the same loaded swf by doing this:

  // re-use a loaded swf
  var bytes:ByteArray = existingLoader.content.loaderInfo.bytes;
  var loader:Loader = new Loader();
  loader.loadBytes(bytes);

在这里existingLoader是您用于加载在首位swf的加载器。

where existingLoader is the Loader that you used to load the swf in the first place.

loadBytes 中所使用的装载机将派出另一完成事件,所以,当你犯了一个侦听器,你可以使用克隆版本:

The Loader used with loadBytes will dispatch another COMPLETE Event, so when you make a listener for that, you can use the 'cloned' version:

  loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onSWFClonedComplete);
 
精彩推荐
图片推荐