可能这是一个新手问题:) 但我有一些内置在AS3中的Flash游戏。 我想将它导入Flash Builder 4.5以创建这些游戏的Andorid,iOS版本。
是否可以将此游戏导入Flash Builder并运行类似“为Android编译”的内容?
如果可能,我该怎么做?
Best,Flavio
答案 0 :(得分:1)
如果您的.swf大部分或全部是在时间轴上创建的而不是可移植代码,您只需创建一个包装器和/或预加载器来加载.swf并将其添加到显示列表中。像这样的东西:
package
{
//Imports
import flash.display.Loader;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.net.URLRequest;
//Class
[SWF(backgroundColor = "0x444444")]
public class SwfAirWrapper extends Sprite
{
//Constructor
public function SwfAirWrapper()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.frameRate = 60;
init();
}
//Initialize
private function init():void
{
var swfLoader:Loader = new Loader();
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteEventHandler);
swfLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loaderProgressEventHandler);
swfLoader.load(new URLRequest("MyGame.swf");
}
//Loader Progress Event Handler
private function loaderProgressEventHandler(evt:ProgressEvent):void
{
//preloader stuff goes here
//IE: evt.bytesTotal / evt.bytesLoaded * 100)
}
//Loader Complete Event Handler
private function loaderCompleteEventHandler(evt:Event):void
{
//Load complete stuff goes here
//IE: addChild(evt.currentTarget.content);
}
}
}
或者如果你不想要预装载器,你可以简单地嵌入你的swf。像这样的东西:
package
{
//Imports
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
//Class
[SWF(backgroundColor = "0x444444")]
public class SwfAirWrapper extends Sprite
{
//Variables
[Embed(source = "mySwf.swf")]
private var EmbeddedSwf:Class;
//Constructor
public function SwfAirWrapper()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.frameRate = 60;
init();
}
//Initialize
private function init():void
{
var mySwf:DisplayObject = new EmbeddedSwf();
addChild(mySwf);
}
}
}