1

変換ツールに表示されるコントロールに問題があります。画像をクリックすると、(画像をスケーリングまたは回転するための) 境界ボックスが表示されますが、コーナーにカーソルを合わせると、カーソルが変換されません。

境界ボックスのある画像

私はこれらのファイルを使用しています:

TransformTool.as

TransformToolControl.as

TransformToolCursor.as

これは変換ツールを呼び出すための私のコードです:

var tool:TransformTool = new TransformTool();
    addChild(tool);

そして、これは後で画像がクリックされたときにツールが表示され、ステージがクリックされたときにツールが非表示になるようにします:

tmpImage.addEventListener(MouseEvent.CLICK, select);

function select(e:MouseEvent):void {
        tool.target = e.currentTarget as Sprite;
        stage.addEventListener(MouseEvent.MOUSE_DOWN, deselect);
    }

function deselect(e:MouseEvent):void {
        tool.target = null;
        tmpImage.addEventListener(MouseEvent.CLICK, select);
    }

境界ボックスの表示と非表示の画像選択は完全に機能します。私のコードはすべて期待どおりに機能します....バウンディングボックスの実際のコントロールを除きます。助けてください!

編集

コンセプトは、ユーザーがメニューから画像をクリックして、その画像の新しいインスタンスをステージにドラッグできることです。その後、ユーザーは新しいインスタンスをクリックして、回転またはスケーリングできるようになります。次に、画像をクリックして境界ボックスを非表示にすることができます。(必要な数の画像をステージに追加できます)。

これは、基本的なクリック、新しいインスタンスの作成、および実装したドラッグ プロセスを示すコードです。

        //sb1 is the menu area that contains a group of images
        //hill is one of the images the user can add to the stage
        sb1.hill.addEventListener(MouseEvent.MOUSE_DOWN, createCopy);
            var i:int=0;
            var tmpImage:Sprite; //to store which image is being dragged currently

        function createCopy(e:MouseEvent):void {
            tmpImage = new Hill_mc();
            tmpImage.name = "hillChild"+(i++); //increment every copy
            container.addChild(tmpImage);
            tmpImage.x = mouseX-470;
            tmpImage.y = mouseY-270;
            tmpImage.startDrag();
            tmpImage.addEventListener(MouseEvent.MOUSE_DOWN, onDown); //add the mouse down to this new object
            stage.addEventListener(MouseEvent.MOUSE_UP, onUp); //since the mouse is currently down, we need to listen for mouse up to tell the current copy to stop dragging
        }

        //this will be called when click a copy
        function onDown(e:MouseEvent):void {
            tmpImage = Sprite(e.currentTarget); //get a reference to the one that was clicked, so we know which object to stop dragging on the global mouse up.
            container.addEventListener(MouseEvent.MOUSE_UP, onUp); //listen for the mouse up
            tmpImage.startDrag();
        }
        function onUp(e:MouseEvent):void {
            container.removeEventListener(MouseEvent.MOUSE_UP,onUp);
            if (tmpImage.hitTestObject(thesubmenu1)) {
                container.removeChild(tmpImage);
            }
            else {
                tmpImage.stopDrag();
            }
            tmpImage.addEventListener(MouseEvent.CLICK, select);
        }
        function select(e:MouseEvent):void {
            tool.target = e.currentTarget as Sprite;
            tmpImage.addEventListener(MouseEvent.MOUSE_DOWN, deselect);
        }

        function deselect(e:MouseEvent):void {
            tool.target = null;
            tmpImage.addEventListener(MouseEvent.CLICK, select);
        }

編集

このコードを見つけて、TransformTool.as に配置しました。null オブジェクト参照のエラーが発生するため、何かが間違って呼び出されているに違いないと感じています。

    public function select(event:Event):void {
        // the selected object will either be the
        // event target or current target. The current
        // target is checked first followed by target.
        // The parent of the target must match the
        // parent of the tool to be selected this way.

        if (event.currentTarget != this 
        && event.currentTarget.parent == parent){

            setTarget(event.currentTarget as DisplayObject, event);

        }else if (event.target != this 
        && event.target.parent == parent){

            setTarget(event.target as DisplayObject, event);

        }
    }

    /**
     * Helper selection handler for deselecting target objects. Set this
     * handler as the listener for an event that would cause the
     * deselection of a target object.
     * It is not required that you use this event handler. It is only a 
     * helper function that can optionally be used to help ease 
     * development.
     */
    public function deselect(event:Event):void {
        if (_target != null && event.eventPhase == EventPhase.AT_TARGET){
            setTarget(null, null);
        }
    }
4

1 に答える 1