ActionScript 3/MXML:我的代码没有做任何事情

ActionScript 3 / MXML : My code doesn't do anything

将我的代码编译成 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

因为形状不符合小时候的条件。仔细阅读:

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);
}