AS3>开始对某些框架类? [英] AS3 > Starting class on certain frame?

查看:92
本文介绍了AS3>开始对某些框架类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个AS文件,并用它作为一类,里面我叫按钮和幻灯片播放的图像。

之后,我决定通过移动时间线来创建一个前奏。我的问题是,所有的对象都将显示在第一帧,有没有办法一定的帧之后,使整个班级开始?

code,以供参考:

 包{

  进口flash.display.Loader;
  进口flash.net.URLRequest;
  进口对象类型:flash.events.Event;
  进口flash.display.Sprite;
  进口flash.events.MouseEvent;
  进口的flash.display.MovieClip;


  公共类游戏扩展了影片剪辑{

    私人VAR装载机:装载机=新的Loader();

    私人VAR图片:数组= [IMG / Layer_1.jpg,I​​MG / Layer_2.jpg,I​​MG / Layer_3.jpg,I​​MG / Layer_4.jpg,I​​MG / Layer_5.jpg,I​​MG / 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];
    私人VAR triangleButton:三角=新的三角形;
    私人VAR squareButton:万=新的广场;
    私人VAR crossButton:十字=新的交叉;
    私人VAR circleButton:圈=新的循环;


    公共职能发挥(){
      loadNextImage();

      的addChild(装载机);
      loader.x = 137;
      loader.y = 65;

      //按钮
      的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);


    }
    公共职能slideGames(事件:MouseEvent)方法:无效{
      loadNextImage();
    }

    公共职能loadNextImage():无效{
      //增加图像
      _imageIndex ++;

      //如果我们已经达到了数组末尾,重新开始
      如果(_imageIndex> = images.length){
        _imageIndex = 0;
      }

      //现在得到的阵列图像源,并告诉加载器加载它
      VAR的ImageSource:字符串=图像[_imageIndex]为String;
      loader.load(新的URLRequest(ImageSource的));
    }
    //下一张图片显示
    保护VAR _imageIndex:= -1;
  }
}
 

解决方案

是的,而不是在类的构造函数(播放())初始化一切,你可以其移动到另一个函数,调用从时间线上。我使用的是播放类作为文档类假设。

因此​​,而不是

 公共职能发挥(){
 

您将其重命名为

 公共职能play_start(){
 

在这一点上创建命名一个空的构造玩(),如果你想。

在闪光灯的IDE中,选择要显示的项目框架,然后创建一个关键帧也是如此。 选择关键帧,然后转到动作面板(F9)并输入以下code:

  this.play_start();
 

在播放头是关键帧,你的code应该被执行。

I created an AS file and used it as a class, inside it I called buttons and slideshow images.

After that I decided to create an intro by moving the timeline. My problem is that all the objects are displayed from the very first frame, is there a way to make the entire class start after certain frame?

Code for reference:

    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;
  }
}

解决方案

Yes, instead of initializing everything in the constructor of your class (play()), you can move it to another function, and call that from the timeline. I am assuming you are using the play class as the document class.

So instead of

public function play() {

you would rename it to

public function play_start() {

Create an empty constructor named play() at this point if you want to.

In the flash IDE, select the frame where you want the items to appear, then create a keyframe there. Select the keyframe and go to the Actions panel (F9) and enter the following code:

this.play_start();

once the playhead is at the keyframe, your code should be executed.

这篇关于AS3>开始对某些框架类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆