2017-06-05 54 views
0

编译我的代码到一个程序,什么都不做的SWF文件的结果。我期待一个颜色为#FFAA00的纯色矩形。为什么我的代码没有做任何事情?的ActionScript 3/MXML:我的代码没有做任何事情

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 

回答

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

一些代码将是很好的。 – Yoshimaster

+1

@Yoshimaster您无法创建某个类的实例并将其添加为中间容器? Okaaay ... – Organis

+0

就是这样?对不起,我有点困惑。我不经常使用OOP语言,因此并不真正了解术语。基本上,我不明白你的意思。 – Yoshimaster