Question

I am using greescock code for as3 and I simply want to annimate a movie from a class. The movie is called content in the About class where this code it.

As you can see my content is called "content" and I am replacing the mc var here with content. Hoping this would work but nothing.

Any ideas how to use Greensock as3 and how to scroll content?

 var mc:Sprite = getChildByName("content") as MovieClip;


package com.views
{

    import flash.display.MovieClip;
    import com.greensock.*;
    import com.greensock.easing.*;
    import com.greensock.plugins.*;
    import flash.geom.Rectangle;
    import flash.utils.getTimer;
    import flash.events.MouseEvent;
    import flash.text.*;
    import flash.display.*;
    TweenPlugin.activate([ThrowPropsPlugin]);


    public class viewAbout extends MovieClip
    {


        public function viewAbout()
        {



            var bounds:Rectangle = new Rectangle(0,100,1080,1920);
            var mc:Sprite = getChildByName("content") as MovieClip;
            //setupTextField(mc, bounds);
            var blitMask:BlitMask = new BlitMask(mc,bounds.x,bounds.y,bounds.width,bounds.height,false);

            var t1:uint,t2:uint,y1:Number,y2:Number,yOverlap:Number,yOffset:Number;

            blitMask.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

            function mouseDownHandler(event:MouseEvent):void
            {
                TweenLite.killTweensOf(mc);
                trace("DOWN DOWN mouse");

                //blitMask.alpha = .3;

                y1 = y2 = mc.y;
                yOffset = this.mouseY - mc.y;

                yOverlap = Math.max(0,mc.height - bounds.height);
                t1 = t2 = getTimer();
                mc.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
                mc.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
            }

            function mouseMoveHandler(event:MouseEvent):void
            {

                trace("Move Event");
                var y:Number = this.mouseY - yOffset;
                //if mc's position exceeds the bounds, make it drag only half as far with each mouse movement (like iPhone/iPad behavior)
                if (y > bounds.top)
                {
                    trace("Somethign ?");
                    mc.y = (y + bounds.top) * 0.5;
                }
                else if (y < bounds.top - yOverlap)
                {
                    mc.y = (y + bounds.top - yOverlap) * 0.5;
                }
                else
                {
                    mc.y = y;
                }
                blitMask.update();
                var t:uint = getTimer();
                //if the frame rate is too high, we won't be able to track the velocity as well, so only update the values 20 times per second
                if (t - t2 > 50)
                {
                    y2 = y1;
                    t2 = t1;
                    y1 = mc.y;
                    t1 = t;
                }
                event.updateAfterEvent();
            }

            function mouseUpHandler(event:MouseEvent):void
            {
                trace("UP UP UP! ");
                mc.stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
                mc.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
                var time:Number = (getTimer() - t2) / 1000;
                var yVelocity:Number = (mc.y - y2) / time;
                ThrowPropsPlugin.to(mc, {throwProps:{
                 y:{velocity:yVelocity, max:bounds.top, min:bounds.top - yOverlap, resistance:300}
                 }, onUpdate:blitMask.update, ease:Strong.easeOut
                }, 10, 0.3, 1);
            }



            // constructor code
        }
    }

}
Was it helpful?

Solution

I found a way to put it in a function and send a var as the name of the mc I want to control. So far this works great. I am sure someone from greensock might say I am doing something that I should not but here goes.

Note my var screenX is a var from the stage.StageWidth and the menuBanner.width is just moving the mc down on the screen. Keep this in mind as you use this function. Hope it helps someone.

Need the proper imports:

import flash.display.MovieClip;
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
import flash.geom.Rectangle;
import flash.utils.getTimer;
import flash.events.MouseEvent;
import flash.text.*;
import flash.display.*;
TweenPlugin.activate([ThrowPropsPlugin]);

To call it use:

throwIt(yourMC);


public function throwIt(clipContent:MovieClip)
        {
            var bounds:Rectangle = new Rectangle(screenX - clipContent.width,0,1080,1920);
            //var mc:Sprite = clipContent.getChildByName("content") as MovieClip;
            var mc:Sprite = clipContent as MovieClip;
            addChild(mc);

            //some variables for tracking the velocity of mc
            var t1:uint,t2:uint,y1:Number,y2:Number;

            mc.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

            function mouseDownHandler(event:MouseEvent):void
            {
                TweenLite.killTweensOf(mc);
                y1 = y2 = mc.y;
                t1 = t2 = getTimer();
                mc.startDrag(false, new Rectangle(bounds.x, -99999, 0, 99999999));
                mc.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
                mc.stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
            }

            function enterFrameHandler(event:Event):void
            {
                //track velocity using the last 2 frames for more accuracy
                y2 = y1;
                t2 = t1;
                y1 = mc.y;
                t1 = getTimer();
            }

            function mouseUpHandler(event:MouseEvent):void
            {
                mc.stopDrag();
                mc.stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
                mc.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
                var time:Number = (getTimer() - t2) / 1000;
                var yVelocity:Number = (mc.y - y2) / time;
                var yOverlap:Number = Math.max(0,mc.height - bounds.height);
                ThrowPropsPlugin.to(mc, {ease:Strong.easeOut, throwProps:{y:{velocity:yVelocity, max:bounds.top+menuBanner.height, min:bounds.top - yOverlap, resistance:100}}}, 3, 0.25, .3);
            }
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top