Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 如何使用源代码将电影剪辑添加到特定帧中的舞台(包括整个it';的事件)?_Actionscript 3_Flash_Flash Cs5 - Fatal编程技术网

Actionscript 3 如何使用源代码将电影剪辑添加到特定帧中的舞台(包括整个it';的事件)?

Actionscript 3 如何使用源代码将电影剪辑添加到特定帧中的舞台(包括整个it';的事件)?,actionscript-3,flash,flash-cs5,Actionscript 3,Flash,Flash Cs5,这是我的角色类,我想要的角色电影剪辑,其中引用这个类可以添加到特定的框架阶段。因此,当我单击按钮开始时,它将添加角色的movieclip。如果有人能帮助我,我将不胜感激 package com.ply { import flash.display.MovieClip; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.ui.Keyboard;

这是我的角色类,我想要的角色电影剪辑,其中引用这个类可以添加到特定的框架阶段。因此,当我单击按钮开始时,它将添加角色的movieclip。如果有人能帮助我,我将不胜感激

package com.ply 
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;

import flash.ui.Keyboard;

public class Heli extends MovieClip
{
    //Settings
    public var xAcceleration:Number = 0;
    public var yAcceleration:Number = 0;
    private var xSpeed:Number = 0;
    private var ySpeed:Number = 0;

    private var up:Boolean = false;
    private var down:Boolean = false;
    private var left:Boolean = false;
    private var right:Boolean = false;

    private var bullets:Array;
    private var missiles:Array;


    public function Heli()
    {
        init();
    }

    private function init():void
    {
        addEventListener(Event.ENTER_FRAME, runGame);           
    }

    private function runGame(event:Event):void
    {
        xSpeed += xAcceleration ;       //increase the speed by the acceleration
        ySpeed += yAcceleration ;       //increase the speed by the acceleration

        xSpeed *= 0.95;                 //apply friction
        ySpeed *= 0.95;                 //so the speed lowers after time

        if(Math.abs(xSpeed) < 0.02)     //if the speed is really low
        {
            xSpeed = 0;                 //set it to 0
                                //Otherwise I'd go very small but never really 0
        }
        if(Math.abs(ySpeed) < 0.02)     //same for the y speed
        {
            ySpeed = 0;
        }

        xSpeed = Math.max(Math.min(xSpeed, 10), -10);       //dont let the speed get bigger as 10
        ySpeed = Math.max(Math.min(ySpeed, 10), -10);       //and dont let it get lower than -10

        this.x += xSpeed;               //increase the position by the speed
        this.y += ySpeed;               //idem

    }

    /**
     * Keyboard Handlers in main class 
     */

}
package com.ply
{
导入flash.display.MovieClip;
导入flash.display.Sprite;
导入flash.events.Event;
导入flash.events.MouseEvent;
导入flash.ui.Keyboard;
公共类直升机扩展MovieClip
{
//背景
公共变量X加速度:数值=0;
公共变量Y加速度:数值=0;
私有变量xSpeed:Number=0;
私有变量ySpeed:Number=0;
private-var-up:Boolean=false;
private-var-down:Boolean=false;
私有变量left:Boolean=false;
private-var-right:Boolean=false;
私有变量:数组;
私人var导弹:阵列;
公共职能部门
{
init();
}
私有函数init():void
{
addEventListener(Event.ENTER_FRAME,runGame);
}
私有函数runGame(事件:事件):void
{
xSpeed+=xAcceleration;//通过加速度增加速度
ySpeed+=YAAcceleration;//通过加速度增加速度
xSpeed*=0.95;//施加摩擦力
ySpeed*=0.95;//因此速度会随着时间的推移而降低
if(Math.abs(xSpeed)<0.02)//如果速度真的很低
{
xSpeed=0;//将其设置为0
//否则我会变得很小,但永远不会真正的0
}
if(Math.abs(ySpeed)<0.02)//y速度相同
{
y速度=0;
}
xSpeed=Math.max(Math.min(xSpeed,10),-10);//不要让速度变大到10
ySpeed=Math.max(Math.min(ySpeed,10),-10);//不要让它小于-10
this.x+=xSpeed;//按速度增加位置
this.y+=ySpeed;//idem
}
/**
*主类中的键盘处理程序
*/
}

}我不完全理解这里的问题,你想做什么,但试试这个。将构造函数更改为以下代码:

public function Heli()
{
   addEventListener(Event.ADDED_TO_STAGE, init);
}
然后,将init()函数更改为
init(e:Event):void
。这将确保在将MovieClip添加到stage之后完成任何初始化。哦,在init()函数的顶部添加以下行:
removeEventListener(Event.ADDED_至_阶段,初始化)


然后,在按钮开始的事件处理程序中,创建类的新实例,并将其添加到阶段(或父容器,取决于游戏结构)。

如果要在特定帧中添加角色,请执行此操作。你有两种方法:

  • 使用计时器创建角色类Heli()的实例

    var定时器:定时器=新定时器(计数秒,重复参数)
    timer.addEventListener(TimerEvent.timer\u COMPLETE,onEventHandler)
    timer.start()

    函数onEventHandler(e:TimerEvent):void
    {在这里创建直升机的不稳定状态}

  • 您可以在EnterFrame处理程序中对帧进行计数,并在一些计数值之后创建角色Heli的实例


  • 如果你使用的是相框,为什么不在设计时把电影剪辑放到舞台上呢?