携帯電話にActionscript2.0を使用していますが、イベントに頭を悩ませることができません。
私はすべてのコードでクラスオブジェクトを作成し、関数のグループを使用しています(すべてクラスの直接の第1レベルの子として)。正方形が付いたムービークリップを作成し、onPressイベントをhitと呼ばれる別の関数に設定する関数が1つあります。
public function draw1Sqr(sName:String,pTL:Object,sSide:Number,rgb:Number){
// create a movie clip for the Sqr
var Sqr:MovieClip=this.canvas_mc.createEmptyMovieClip(sName,this.canvas_mc.getNextHighestDepth());
// draw square
Sqr.beginFill(rgb);
//etc ...more lines
//setup properties (these are accessible in the event)
Sqr.sSide=sSide;
Sqr.sName=sName;
//setup event
Sqr.onPress = hit; // this syntax seems to lead to 'this' within
// the handler function to be Sqr (movieclip)
//Sqr.onPress = Delegate.create(this, hit);
//I've read a lot about Delegate but it seems to make things harder for me.
}
次に、イベントハンドラーで、スコープを正しく取得できません...
public function hit(){
for (var x in this){
trace(x + " == " + this[x]);
}
//output results
//onPress == [type Function]
//sName == bSqr_7_4
//sSide == 20
trace(eval(this["._parent"])); //undefined
trace(eval(this["._x"])); //undefined
}
何らかの理由で、スコープが呼び出し元のオブジェクト(Sqr、Movieclip)に設定され、定義したプロパティにアクセスできますが、Movieclipオブジェクトの「ネイティブ」プロパティを使用できません。
押されたMovieclipオブジェクトの_x、_y、およびその他のプロパティにアクセスする方法に関する提案。