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 Flash cs6 as3:以编程方式更改与类关联的movieclip,而不使用该类的实例_Actionscript 3_Flash - Fatal编程技术网

Actionscript 3 Flash cs6 as3:以编程方式更改与类关联的movieclip,而不使用该类的实例

Actionscript 3 Flash cs6 as3:以编程方式更改与类关联的movieclip,而不使用该类的实例,actionscript-3,flash,Actionscript 3,Flash,我正在制作一个游戏。我希望我的主角能够通过编程来装备武器/盔甲之类的东西。他有一只手,如果我手动编辑一把剑,动画效果很好,但是我不希望他从装备剑开始 不幸的是,我无法访问此手的实例,因为它在攻击动画期间仅出现10帧。如果在时间轴帧110-120中为手设置实例名称,则无法从角色类中引用它 有没有一种方法可以访问我的arm类并以编程方式将我的剑精灵添加到关联的movieclip中,而不必访问arm类的实例?我曾考虑过将手臂movieclip换成一个已经添加了剑的movieclip,但我遇到了同样的问

我正在制作一个游戏。我希望我的主角能够通过编程来装备武器/盔甲之类的东西。他有一只手,如果我手动编辑一把剑,动画效果很好,但是我不希望他从装备剑开始

不幸的是,我无法访问此手的实例,因为它在攻击动画期间仅出现10帧。如果在时间轴帧110-120中为手设置实例名称,则无法从角色类中引用它

有没有一种方法可以访问我的arm类并以编程方式将我的剑精灵添加到关联的movieclip中,而不必访问arm类的实例?我曾考虑过将手臂movieclip换成一个已经添加了剑的movieclip,但我遇到了同样的问题,即无法访问仅在某些帧中出现的实例


我试着让我的问题尽可能清楚,希望它能奏效。非常感谢您提供的任何见解

这里是最简单但不是最好的方法

在主根时间线上,放置以下代码:

var weaponId:int = 1;  //never modify this directly, use the function below so the event gets dispatached. - This value will correspond to frame in your weapon movieClip that will contain the correct graphic of the selected weapon.

function changeWeapon(id:int):void {
    weaponId = id;
    this.dispatchEvent(new Event("WeaponChange")); //this will dispatch an event, so anything listening for this event will know it's been changed
}
MovieClip(root).addEventListener("WeaponChange",updateWeapon,false,0,true); //listen for when the weapon changes

updateWeapon(); //update the weapon immediately to the current value

function updateWeapon(e:Event = null):void {
    weapon.gotoAndStop(MovieClip(root).weaponId); //assuming your hand timeline has a movieClip on it called weapon and each frame of weapon corresponds to the weaponId
}
在您的手上,输入以下代码:

var weaponId:int = 1;  //never modify this directly, use the function below so the event gets dispatached. - This value will correspond to frame in your weapon movieClip that will contain the correct graphic of the selected weapon.

function changeWeapon(id:int):void {
    weaponId = id;
    this.dispatchEvent(new Event("WeaponChange")); //this will dispatch an event, so anything listening for this event will know it's been changed
}
MovieClip(root).addEventListener("WeaponChange",updateWeapon,false,0,true); //listen for when the weapon changes

updateWeapon(); //update the weapon immediately to the current value

function updateWeapon(e:Event = null):void {
    weapon.gotoAndStop(MovieClip(root).weaponId); //assuming your hand timeline has a movieClip on it called weapon and each frame of weapon corresponds to the weaponId
}
下面是正在发生的事情:


无论何时更改武器,不管如何,都要调用根时间轴上的函数changebarm。这将设置变量并分派事件。如果手存在,它将看到事件并更新自身。如果手部不存在,下一步实例化手部时,它将查看全局变量并相应更改。

只要始终保持手部和剑的存在,并根据需要更改其可见属性。如果我最终拥有100多种不同的武器,这是最好的方法吗?我并不打算这么做,但我很好奇这是否是传统的做法。你需要展示你的代码,说明你目前如何向任何人提供帮助。传统的做法是使用类文件而不是时间线代码,因为时间线代码很笨拙。最好的方法是在你的手臂/手类或时间轴中设置代码,在创建时运行代码,以了解它是否应该有剑以及应该有哪一把剑,并根据需要创建它。RE:100+武器的可见性-如果有一个主剑电影剪辑,并将你的剑作为时间轴的不同帧,那就好了,那么您在任何时候都只加载了一个实例。