我刚刚在我的代码中发现了一个错误,即类 Player 没有引发 creationComplete 事件。
网格.mxml:
m_arrSpaces[4][4].entities.addItem(new Player());
播放器.mxml:
<?xml version="1.0" encoding="utf-8"?>
<Entity xmlns="entities.*" xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="onCreationComplete">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function onCreationComplete():void {
Alert.show("cration");
m_imgActiveImage = imgUp;
}
]]>
</mx:Script>
我知道 Grid.mxml 中的行正在运行,并且 Player 对象正在添加到 m_arrSpaces[4][4].entities。我也知道 Player.onCreationComplete() 永远不会被调用。什么?
编辑:等等,即使我更正错字并在 MXML 标记中包含括号,它也在做同样的事情,如:
creationComplete="onCreationComplete()"
编辑:哦,是的,这是实体的代码:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="onCreationComplete()">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Image;
import spaces.Space;
protected var m_imgActiveImage:Image;
public function get activeImage():Image {
return m_imgActiveImage;
}
private function onCreationComplete():void {
width = Space.SPAN - 4;
height = width;
}
]]>
</mx:Script>
</mx:Canvas>