这很容易做到。
在我看来,组成部分是错误的做法。
Firstly you would want to setup Actionscript linkage / label your Library item.
In Library Panel.
- Right Click on "yourMC" >> click "Properties".
- In Properties dialog Tick "Export for Action Script"
- Then Name your Class eg "yourMC_Class"
监控监已经准备好在你的代码中被引用了
next you would want to Dynamically add your "yourMC" from library to stage.
which can be done like such.
/第一个参考图书馆项目
var yourMC_ref:yourMC_Class = new yourMC_Class();
/ 然后将动态 mc 项装入 var 。
var your_MC_OBJ = yourMC_ref;
/然后把你的MC添加到舞台上。
this.addChild(your_MC_OBJ);
your_MC_OBJ.x = 200;
your_MC_OBJ.y = 100;
简而言之,这就是我如何把图书馆项目添加到舞台上。
显然,这是基本功能/代码。
在一个项目中,我会拥有所有代码 在一个外部阶级, 在这样的情况下,你会 仅仅设置vars作为公共vars
public var yourMC_ref:yourMC_Class = new yourMC_Class();
public var your_MC_OBJ = yourMC_ref;
最后三行代码变成公共职能
public function ADD_First_MC()
{
this.addChild(your_MC_OBJ);
your_MC_OBJ.x = 200;
your_MC_OBJ.y = 100;
}
现在您可以用更复杂的 MC_ OBJ 方式使用 。
eg. to create a light switch there are many options depending on how you need to approch functionality.
eg. Apply a different MC library item to "your_MC_OBJ"
play specific frame within MCs.
However If it was me I would just use mouse function to switch light on or off using addChild removeChild.
eg.
public var LightON = 0;
public var yourMC_ref:yourMC_Class = new yourMC_Class();
public var your_MC_OBJ = yourMC_ref;
然后创建一个公共函数, 处理/ 关闭事件
public function LightON_OFF()
{
if(LightON == 1)
{
this.addChild(your_MC_OBJ);
your_MC_OBJ.x = 200;
your_MC_OBJ.y = 100;
}
if(LightON == 0)
{
this.removeChild(your_MC_OBJ);
}
}
希望这能帮上忙