我正在尝试将我的对象的一些基本功能移到外部包。
我的库中有一个名为mcUnit的MovieClip项目:实际上是一个F8-Move in Move Clip。 我正在将AS Linkage设置为我想要它使用的包:clGameUnit;
以下是clGameUnit代码的一部分:
package
{
import flash.display.MovieClip;
import flash.geom.Point;
import flash.events.MouseEvent;
public class clGameUnit extends MovieClip
{
// Declaring all local object related variable
var clGU:MovieClip = new MovieClip();
var isOver:Boolean = false;
// Declaring all global object related variable
public var b_u_Selected:Boolean = false;
public var p_u_Coordinates:Point = new Point();
public var u_Image:int = 0;
//Declaring all object related methods
clGU.addEventListener (MouseEvent.CLICK, on_Object_LClick);
clGU.addEventListener (MouseEvent.MOUSE_OVER, onObjectMouseOver);
clGU.addEventListener (MouseEvent.MOUSE_OUT, onObjectMouseOut);
clGU.addEventListener (MouseEvent.RIGHT_CLICK, on_Object_RClick);
public function clGameUnit ()
{
}
....
}
}
错误我明白了:
1120: Access of undefined property clGU.
1120: Access of undefined property on_Object_LClick.
1120: Access of undefined property ... [other event listeners functions]
已经尝试了一切。甚至使构造函数将对象发送到未定义的属性clGU:
public function clGameUnit (obj: MovieClip)
{
clGU = obj;
}
在时间线上,我手动调用此构造函数:
var mcGameObj: clGameUnit = new clGameUnit (mcGUnit);
mcGUnit是我在属性中分配的mcUnit实例的实例名称。 事情变得更加复杂,所以我放弃了这个变种。
如果需要上传我的项目,请高兴地这样做!
真的需要你的帮助fellaz!
答案 0 :(得分:1)
将这些行放入函数
clGU.addEventListener (MouseEvent.CLICK, on_Object_LClick);
clGU.addEventListener (MouseEvent.MOUSE_OVER, onObjectMouseOver);
clGU.addEventListener (MouseEvent.MOUSE_OUT, onObjectMouseOut);
clGU.addEventListener (MouseEvent.RIGHT_CLICK, on_Object_RClick);
例如
public function clGameUnit () {
init();
}
private function init():void {
clGU.addEventListener (MouseEvent.CLICK, on_Object_LClick);
clGU.addEventListener (MouseEvent.MOUSE_OVER, onObjectMouseOver);
clGU.addEventListener (MouseEvent.MOUSE_OUT, onObjectMouseOut);
clGU.addEventListener (MouseEvent.RIGHT_CLICK, on_Object_RClick);
}