0

画像がカーソルとして機能するアプリケーションに取り組んでいます。ここで、カーソルがどのオブジェクト上にあるかをいつでも知りたいと思います。HitTestObject(*)のようなもので、*が表すオブジェクトを確認できます。誰かが私がこれをどのように達成できるか考えていますか?(そしてマウスを使用することはオプションではありません)

4

2 に答える 2

1

「ホバリング」を監視する要素を別の配列に配置し、マウスに接続されたオブジェクトに onEnterFrame リスナーを追加します。これは、配列を反復処理し、各オブジェクトで hitTests を実行します。

var hitTestClips:Array;
// populate hitTestClips with the items you want to hitTest

これは、マウスにアタッチされたオブジェクトの onEnterFrame ハンドラーに入ります。

for(var item:MovieClip in hitTestClips)
{
  if(item.hitTest(this.x, this.y, true))
  {
    trace('now hovering above ' + item);
  }
}
于 2011-04-06T14:19:06.190 に答える
1

私はすでに問題を解決しました:)カーソルが他のスプライトとは異なるスプライトにあったため、ホバーするオブジェクトを配列に渡すことができなかったため、このようにする必要がありました。

        //First we will create a point that contains the x and y of this cursor.
        var _position:Point = new Point(x + (width/2), y + (height/2));

        //Secondly, we will get an array of elements that are under this point.
        var _objects:Array = parentApplication.getObjectsUnderPoint(_position);

        //If the length of the objectsList is longer than or equal to 2, we may assume that
        //there is an object
        if(_objects.length >= 2)
        {
            //Set the currentObject variable to the object the cursor is hovering over.
            //The minus two is simple. The cursor is always the last object under that point,
            //so we need the object before that.
            _currentObject = _objects[_objects.length - 2];

            //dispatch the event in the object.
            dispatchCursorEventToObject(EyeEvent.CURSOROVER);
        }
于 2011-04-06T14:49:13.307 に答える