tomtom123456
tomtom123456

Reputation: 11

Actionscript 3 scaling

I've recently started coding in Actionscript 3, and I've run into a problem when trying to scale a MovieClip.

{
    private var valGrandX:Number;
    private var valGrandY:Number;
    public function Bonhomme_Fil()
    {
        valGrandX = this.scaleX;
        valGrandY = this.scaleY;

        this.addEventListener(MouseEvent.ROLL_OVER, big);
        this.addEventListener(MouseEvent.ROLL_OUT, small);
    }
    private function big(event:MouseEvent):void
    {
        this.scaleX *=  1.5;
        this.scaleY *=  1.5;
    }
    private function small(event:MouseEvent):void
    {
        this.scaleX = valGrandX;
        this.scaleY = valGrandY;
    }
}

My goal is to have the Clip become larger when the user's mouse hovers over it, and return to its normal size when he hovers outside of it. What ends up happening is that when it scales to a bigger size it moves towards the bottom and right, and ends up flickering back and forth.

Upvotes: 1

Views: 636

Answers (3)

Nemi
Nemi

Reputation: 1032

Try using MouseEvent.MOUSE_OVER and MouseEvent.MOUSE_OUT.

Check what is the difference between roll over and mouse over?

Or set code like this:

private var valGrandX:Number;
private var valGrandY:Number;
public function Bonhomme_Fil()
{
    valGrandX = this.scaleX;
    valGrandY = this.scaleY;

    addEventListener(MouseEvent.ROLL_OVER, big);
}
private function big(event:MouseEvent):void
{
    //this.scaleX *=  1.5;
    //this.scaleY *=  1.5;
    this.scaleX =  1.5;
    this.scaleY =  1.5;

    removeEventListener(MouseEvent.ROLL_OVER, big);
    addEventListener(MouseEvent.ROLL_OUT, small);
}
private function small(event:MouseEvent):void
{
    this.scaleX = valGrandX;
    this.scaleY = valGrandY;

    addEventListener(MouseEvent.ROLL_OVER, big);
    removeEventListener(MouseEvent.ROLL_OUT, small);
}

Upvotes: 1

Jeffin
Jeffin

Reputation: 1209

I think the reason is that the x,y value is not changed , please try to refer this post

Upvotes: 1

Organis
Organis

Reputation: 7316

When you design a MovieClip, there is its center marked with small (+). This point is (0,0) of the MovieClip itself and (x,y) of the MovieClip in its parent coordinates. When you scale/rotate this MovieClip with AS3 commands, it scales/rotates around this point. You need to redesign the content of the MovieClip so it is placed equally around its (0,0), then you'll have the effect of "zooming in place".

Also you might want to add a transparent button (with 4th frame - it's its hit area - only) if your MovieClip has "holes" or content inconsistencies for the mouse to fall through.

Upvotes: 1

Related Questions