AS3>某些框架上的课程?

时间:2011-11-11 01:25:13

标签: actionscript-3 class

我创建了一个AS文件并将其用作类,在其中我调用了按钮和幻灯片图像。

之后我决定通过移动时间轴来创建一个介绍。我的问题是从第一帧开始显示所有对象,有没有办法让整个类在特定帧之后启动?

参考代码:

    package {

  import flash.display.Loader;
  import flash.net.URLRequest;
  import flash.events.Event;
  import flash.display.Sprite;
  import flash.events.MouseEvent;
  import flash.display.MovieClip;


  public class play extends MovieClip {

    private var loader:Loader = new Loader();

    private var images:Array = ["img/Layer_1.jpg", "img/Layer_2.jpg", "img/Layer_3.jpg", "img/Layer_4.jpg", "img/Layer_5.jpg", "img/Layer_6.jpg", "img/Layer_7.jpg", "img/Layer_9.jpg", "img/Layer_10.jpg", "img/Layer_11.jpg", "img/Layer_12.jpg", "img/Layer_13.jpg", "img/Layer_14.jpg"];
    private var triangleButton:triangle = new triangle;
    private var squareButton:square = new square;
    private var crossButton:cross = new cross;
    private var circleButton:circle = new circle;


    public function play() {
      loadNextImage();

      addChild(loader);
      loader.x = 137;
      loader.y = 65;

      //Buttons
      addChild(triangleButton);
      triangleButton.width = 28;
      triangleButton.scaleY = triangleButton.scaleX;
      triangleButton.x = 804;
      triangleButton.y = 107;
      triangleButton.addEventListener(MouseEvent.CLICK, slideGames);


      addChild(circleButton);
      circleButton.width = 28;
      circleButton.scaleY = circleButton.scaleX;
      circleButton.x = 825;
      circleButton.y = 130;
      circleButton.addEventListener(MouseEvent.CLICK, slideGames);

      addChild(crossButton);
      crossButton.width = 28;
      crossButton.scaleY = crossButton.scaleX;
      crossButton.x = 804;
      crossButton.y = 155;
      crossButton.addEventListener(MouseEvent.CLICK, slideGames);

      addChild(squareButton);
      squareButton.width = 28;
      squareButton.scaleY = squareButton.scaleX;
      squareButton.x = 780;
      squareButton.y = 130;
      squareButton.addEventListener(MouseEvent.CLICK, slideGames);


    }
    public function slideGames(event:MouseEvent):void {
      loadNextImage();
    }

    public function loadNextImage() : void {
      // Increment the image
      _imageIndex++;

      // If we've reached the end of the array, start over
      if (_imageIndex >= images.length) {
        _imageIndex = 0;
      }

      // Now get the image source from the array and tell the loader to load it
      var imageSource : String = images[_imageIndex] as String;
      loader.load(new URLRequest(imageSource));
    }
    // Next image to display
    protected var _imageIndex : int = -1;
  }
}

1 个答案:

答案 0 :(得分:3)

是的,不是初始化类的构造函数(play())中的所有内容,而是可以将其移动到另一个函数,并从时间轴调用它。我假设您使用play类作为文档类。

所以而不是

public function play() {

你会把它重命名为

public function play_start() {

如果您愿意,此时创建一​​个名为play()的空构造函数。

在Flash IDE中,选择要显示项目的框架,然后在其中创建关键帧。 选择关键帧并转到“动作”面板(F9)并输入以下代码:

this.play_start();

一旦播放头位于关键帧,您的代码就会被执行。