将我的代码编译为SWF文件会导致程序无效。我期待一个颜色为#FFAA00的实心矩形。为什么我的代码没有做任何事情?
dummy.as:
//Dependencies
import flash.display.*;
import flash.events.*;
//Variables
var GlobalTimer:int = 0;
var Rect:Shape = new Shape();
//Game loader function
public function handle():void
{
init();
}
//Init function
public function init():void
{
addChild(Rect);
addEventListener(Event.ENTER_FRAME,loop);
}
//Loop function
public function loop(event:Event):void
{
var CurTimer:int = getTimer();
var FrameDiff:int = CurTimer-GlobalTimer;
GlobalTimer = CurTimer;
Rect.graphics.beginFill(0xFFAA00);
Rect.graphics.drawRect(0,0,640,480);
Rect.graphics.endFill();
}
dummy.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application width="640" height="480" xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="handle()">
<mx:Script source="dummy.as"/>
</mx:Application>
使用编译:
./mxmlc ../../feedsparky/src/dummy/dummy.mxml
答案 0 :(得分:1)
因为形状不符合孩子的条件。仔细阅读:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core/Container.html#addChild()
要将基本Flash显示类添加到Flex显示列表,您需要将 UIComponent 作为其父级。你可以在这里看到继承链:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core/Application.html
var FlashBox:UIComponent = new UIComponent;
var Rect:Shape = new Shape;
//Init function
public function init():void
{
addChild(FlashBox);
FlashBox.addChild(Rect);
addEventListener(Event.ENTER_FRAME, loop);
}