从类方法内部添加 MovieClip
我一直在尝试从类中将影片剪辑添加到我的 .fla 文件中。
我的主 fla 文件:main.fla 动作脚本文件:script.因为
它们位于同一目录中。
script.as 文件如下:
package {
import flash.display.*
public class MyClass extends MovieClip
{
public var target:MovieClip;
public function MyClass()
{
init();
}
public function init() //if this method will be runed only inside class it should be private not public
{
trace('created');
}
public function create()
{
target = new myfan();
target.x = 400;
target.y = 50;
stage.addChild(target);
}
}
}
我使用 create 函数从 main.fla 文件创建添加影片剪辑。
var trying:MyClass = new MyClass();
trying.create();
输出给出“已创建”,但我在输出的 swf 文件中看不到“myfan”影片剪辑。
我一整天都在寻找,但找不到太多。
如何从类文件添加影片剪辑?
感谢您的热心帮助。
I have been trying to add a movieclip to my .fla file from a class.
my main fla file: main.fla
actionscript file: script.as
they stay in the same directory.
script.as file as follows:
package {
import flash.display.*
public class MyClass extends MovieClip
{
public var target:MovieClip;
public function MyClass()
{
init();
}
public function init() //if this method will be runed only inside class it should be private not public
{
trace('created');
}
public function create()
{
target = new myfan();
target.x = 400;
target.y = 50;
stage.addChild(target);
}
}
}
I use create function to create add the movieclip from main.fla file.
var trying:MyClass = new MyClass();
trying.create();
The output give "created" but i connot see "myfan" movieclip inside the outputted swf file.
I have been searching all the day but could not find very much.
How can i add a movieclip from a class file?
Thanks for your kind help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对如何将 script.as 附加到 swf 感到有点困惑。 AS3 中的类必须位于与类名完全相同的文件中 - 因此您的文件首先应命名为 MyClass.as。
第二个问题是
myfan
到底是什么?它是你图书馆里的一个符号吗?该符号包含什么?如果将元件拖到舞台上而不是尝试使用 ActionScript 实例化它,会发生什么情况?最后,如果您要实例化
MyClass
您在哪里这样做?在时间线内电影的第一帧上?我注意到您在任何时候都没有将变量trying
添加到显示列表中......这意味着变量stage
可能为空。尝试添加:看看你是否得到了什么。
I'm a bit confused as to how you are attaching the script.as to the swf. Classes in AS3 must be in a file with the exact same name as the class name - so your file should be named MyClass.as as a first point.
The second question is what is
myfan
exactly? Is it a symbol in your library? What does that symbol contain? What happens if you drag the symbol onto the stage instead of trying to instantiate it using ActionScript?Finally, if you are instantiating
MyClass
where are you doing so? On the first frame of the movie within the timeline? I notice that you aren't adding the variabletrying
onto the display list at any time .... that would mean the variablestage
might be null. Try adding:To see if you get anything.