我和IDE一起战斗,整天阅读,了解到在AS3中,lib符号的导出类名很重要。
我有hello.fla。在其中我创建了一个带有字符串的简单文本字段('hello') - 将其转换为符号(movieclip)并执行以下操作:
有一次,我做了所有我在舞台上的实例。我以为我可能会在以后添加一些额外的功能,所以我实际上还构建了一个Hello.as类,它扩展了MovieClip,它存在于默认的pkg *中并且整个fla构建得很好:
package
{
import flash.display.MovieClip;
public class Hello extends MovieClip
{
public function Hello()
{
}
}
}
现在我的main.fla,同一个文件夹,使用文档类Main,Main.as执行以下操作:
private var h:MovieClip;
//...
h = new Hello();
this.addChild(h); //no joy
**直到我开始工作,文件夹中没有任何内容:所有文件都在根文件夹中。*
答案 0 :(得分:1)
假设库符号存在于.fla中,例如Hello.fla:
package
{
import flash.display.MovieClip;
import flash.text.TextField;
/**
* empty mc (blank stage) with a single library symbol containing whatever the hell you want (eg a shape). with settings:
* class = Hello <=== this refers to a specific library symbol, not the entire Hello.fla and whatever else is on the stage when you build it.
* export for AS : checked
* export for runtime sharing (as Hello.swf) : checked <==== This was the step I'd missed
* export in 1st frame : checked
*/
public class Hello extends MovieClip
{
public function Hello()
{
}
}
}
主要时间表/文件类:
package
{
import flash.display.Loader;
import flash.display.MovieClip;
import flash.net.URLRequest;
import flash.events.Event;
import Hello;
/**
* this is the document class.
*/
public class Main extends MovieClip
{
public function Main()
{
this.h = new Hello();
this.l= new Loader();
this.l.load( new URLRequest("Hello.swf") );
this.l.contentLoaderInfo.addEventListener(Event.COMPLETE, this.test);
}
public function test(e:Event)
{
this.h = new Hello();
h.x = 100;
h.y = 100;
this.addChild(this.h); //shows up on stage. Finally!
}
private var h:MovieClip;
private var l:Loader;
}
}
希望它可以帮助像我这样的其他新手AS3。
答案 1 :(得分:0)
而不是this.addChild(h),如果你尝试root.addChild(h)它会起作用吗?
编辑:_root - &gt; AS3的根
答案 2 :(得分:0)
你需要将它添加到舞台上,即
stage.addChild(h);