Lady_dragon4
Lady_dragon4

Reputation: 91

Tween code on a mask in Actionstipt3 not working

I am trying to make and accordion style menu i flash. I am able to get the screens to move up and down, but i can not get the content to show. I have each screen set up as a Movie clip with a mask in side. I can not get the mask to open up with an "if' statment. Any ideas?

import fl.transitions.Tween;
import fl.transitions.easing.*;

screen01.addEventListener(MouseEvent.CLICK, clickHandler);      
screen02.addEventListener(MouseEvent.CLICK, clickHandler);
screen03.addEventListener(MouseEvent.CLICK, clickHandler);
screen04.addEventListener(MouseEvent.CLICK, clickHandler);      


function clickHandler(event:MouseEvent):void
{
    if(event.target == screen01)
    {
        if(screen01.Makeing_MC.height <=72)
        {
            var tweenMask0:Tween = new Tween(screen01.Makeing_MC, "y", Strong.easeOut, screen01.Makeing_MC.height, screen01.Makeing_MC.height + 250, 2, true);
        }           
        var test0:Tween = new Tween(screen01, "y", None.easeNone, screen01.y, 182, 1, true);
        var test1:Tween = new Tween(screen02, "y", None.easeNone, screen02.y, 539, 1, true);
        var test2:Tween = new Tween(screen03, "y", None.easeNone, screen03.y, 625, 1, true);
        var test3:Tween = new Tween(screen04, "y", None.easeNone, screen04.y, 710, 1, true);
    }
    else if(event.target == screen02)
    {
        var testa:Tween = new Tween(screen01, "y", None.easeNone, screen01.y, 182, 1, true);
        //var maskmove1:Tween = new Tween(screen01.Makeing_MC, "height", Strong.easeOut, screen01.Makeing_MC.height, screen01.Makeing_MC.height - 250, 1, true);

        var test5:Tween = new Tween(screen02, "y", None.easeNone, screen02.y, 265, 1, true);
        var test6:Tween = new Tween(screen03, "y", None.easeNone, screen03.y, 625, 1, true);
        var test7:Tween = new Tween(screen04, "y", None.easeNone, screen04.y, 710, 1, true);
    }
    else if(event.target == screen03)
    {
        var test8:Tween = new Tween(screen02, "y", None.easeNone, screen02.y, 265, 1, true);
        var test9:Tween = new Tween(screen03, "y", None.easeNone, screen03.y, 347, 1, true);
        var test10:Tween = new Tween(screen04, "y", None.easeNone, screen04.y, 710, 1, true);
    }
    else if(event.target == screen04)
    {
        var test11:Tween = new Tween(screen02, "y", None.easeNone, screen02.y, 265, 1, true);
        var test12:Tween = new Tween(screen03, "y", None.easeNone, screen03.y, 347, 1, true);
        var test13:Tween = new Tween(screen04, "y", None.easeNone, screen04.y, 431, 1, true);
    }
}

Upvotes: 1

Views: 69

Answers (1)

Atriace
Atriace

Reputation: 2558

You had the right idea. It looks like you attempted to resize the mask in addition to the position of the MovieClip.

Assuming the structure of your stage looks something like this...

0: MainTimeline
    0: screen01 (MovieClip) // screen01.mask = Makeing_MC?
        0: Makeing_MC (Shape) // <-- our mask?
        1: txt (TextField)
    1: screen02
        0: Makeing_MC (Shape)
        1: txt (TextField)
    2: screen03
        0: Makeing_MC (Shape)
        1: txt (TextField)
    3: screen04
        0: Makeing_MC (Shape)
        1: txt (TextField)

Then animating the height of the mask, and moving the parent clip should be sufficient for your goal.

import fl.transitions.Tween;
import fl.transitions.easing.*;

// We'll keep clip specific information (nice and tidy) in here.
var accordion:Array = [
    {"clip":screen01, "height":357, "y":182},
    {"clip":screen02, "height":360, "y":265},
    {"clip":screen03, "height":363, "y":347},
    {"clip":screen04, "height":360, "y":431}
]


// Loop through and register each clip with mouse events.
for each (var screen:Object in accordion) {
    screen.clip.addEventListener(MouseEvent.CLICK, clickHandler);
}


function clickHandler(e:MouseEvent):void {
     // This is the size of the open accordion.
     // We'll add this to each consecutive clip's "y" property after the clicked one.
    var offsetY:int = 0;

    // Loop through the accordion array
    for each (var screen:Object in accordion) {
        // Set the position of the clip to the "y" value from the appropriate entry, adding our offset.
        screen.tween = new Tween(screen.clip, "y", None.easeNone, screen.clip.y, screen.y + offsetY, 1, true);

        // If this is the clip we clicked on...
        if (screen.clip == e.target) {
            offsetY = screen.height; // Add the opened accordion's height property to the offset
            // and animate open the mask.
            screen.maskTween = new Tween(screen.clip.Makeing_MC, "height", Strong.easeOut, screen.clip.Makeing_MC.height, screen.height, 1, true);
        } else if (screen.clip.Makeing_MC.height != 15) {
            // Otherwise, if its size is not 15, animate it to its "closed" position.
            screen.maskTween = new Tween(screen.clip.Makeing_MC, "height", Strong.easeOut, screen.clip.Makeing_MC.height, 15, 1, true);
        }
    }
}

Upvotes: 2

Related Questions