我目前坚持的情况是我无法在FlashDevelop项目中加载和显示外部swf文件。通常我可以在没有问题的情况下做到这一点,但是这里存在的问题是因为其他人编写了加载包括这个加载swf的每个类的文件。无法动态加载外部SWF?
这里是在加载类的主类的相关代码:(我没有写这个。)
_types = new Vector.<Class>();
_labels = new Vector.<String>();
_types.push(Game1, Game2, Game3, Game4, Game5);
_labels.push("Game1", "Game2", "Game3", "Game4", "Game5");
...有按钮,然后添加到屏幕,引导您这些游戏之一。当点击一个按钮时,此功能被调用:
private function menuSelect(evt:MouseEvent):void
{
if (gameDo[evt.target.name]<2){
gameDo[evt.target.name] ++;
cycle++;
}
_nextQuest = _types[evt.target.name];
}
我打电话的游戏是Game5。当这个类被加载时,它会尝试加载一个具有实际游戏内容的外部swf文件。这里是类:
package
{
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;
/**
* ...
* @author
*/
public class Game5 extends Sprite implements LoaderMod
{
private var _loader:Loader;
public function Game5():void
{
_loader = new Loader();
_loader.load(new URLRequest("Game5.swf"));
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete);
}
public function loader_complete(evt:Event):void
{
var _loadedData:MovieClip = new MovieClip();
_loadedData.addChild(evt.currentTarget.content);
this.addChild(_loadedData);
}
}
当我运行这段代码,这些是我得到的错误:
[Fault] exception, information=TypeError: Error #1034: Type Coercion failed: cannot
convert [email protected] to Quest.
Fault, onEnterFrame() at Main.as:76
[Fault] exception, information=ArgumentError: Error #2025: The supplied DisplayObject
must be a child of the caller.
Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
[Fault] exception, information=ArgumentError: Error #2025: The supplied DisplayObject
must be a child of the caller.
[Fault] exception, information=ArgumentError: Error #2025: The supplied DisplayObject
must be a child of the caller.
而且最后四行中的错误不断产生的游戏运行。至于错误中前两行“不能将Game5 @ 855b0a1转换为Quest”,项目中还有另一个类叫做Quest.as,它被其他类扩展为某种超级类。我写的唯一代码是Game5.as类。
所有帮助表示赞赏。谢谢!
编辑!
这里就是线76的错误是在发生的onEnterFrame()函数:
70 protected function onEnterFrame(evt:Event):void
71 {
72 if (_nextQuest)
73 {
74 removeChild(mainMenu);
75 removeChild(_menu);
76 _quest = new _nextQuest();
77 addChild(_quest);
78 _nextQuest = null;
79 }
80 if (_quest)
81 {
82 if (! _quest.update())
83 {
84 removeChild(_quest);
85 _quest = null;
86 questions.questions();
87 this.addChild(questions);
88 }
89 }
90 }
_nextQuest变量的类型为Class,默认情况下设置为null,直到单击按钮时,menuSelect函数会触发。如果要查找类类型对象,我将如何将_nextQuest的类型更改为Sprite?我试过这个,我得到了错误“类型为flash.display:Sprite的值的隐式强制转换为无关类型的类。”至于一行,这是从输出面板直接复制+粘贴,所以没有其他行号在这里帮助我。你在哪里看到removeChild()在? – hRdCoder
我使用removeChild作为一个例子,我可能会导致“必须是调用者的孩子”错误,但是如果没有更多的信息,这可能是猜测。但是,它看起来像在第76行的Main.as中发生错误。 也许第一个涉及Quest的错误与_nextQuest无关。必须有一些其他的地方,Game5试图在应该使用Quest类型的地方使用。 我注意到Game对象是一个Class类的向量。但是,它添加了Game5,它是Sprite类型。尝试使用数组。 – bandaro
我会尝试。我会将第76行的功能添加到问题中,以便可以清除问题。 – hRdCoder