A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Stuck trying to animate mc's - see code

Threaded View

  1. #1
    Member
    Join Date
    Jul 2009
    Posts
    69

    [RESOLVED] Stuck trying to animate mc's - see code

    Here's the full code, basically there are four shapes in the library. Something's not working in my loop and/or my animateShapes function. The goal is to have the shapes in the loop placed on stage in random colors/transparencies and move around randomly on the stage (varying velocity) while staying within the stage boundaries. Right now, I have one little shape (the first one in the loop, I think) making an anemic motion and the rest don't move at all.

    import flash.display.MovieClip;
    import flash.events.KeyboardEvent;
    import flash.events.Event;
    import flash.text.*;

    var tl:MovieClip = new Topleft();
    var tr:MovieClip = new Topright();
    var bl:MovieClip = new Bottomleft();
    var br:MovieClip = new Bottomright();

    var myShapes:Array = [tl, tr, bl, br];
    //trace(myShapes);

    var xVelocity: Number = 0;
    var yVelocity:Number = 0;


    var long:uint = myShapes.length;
    for (var i:uint = 0; i < long; i++){
    var shape:MovieClip = myShapes[i];
    shape.alpha = 0.3 + Math.random() * 0.9;

    var colorInfo:ColorTransform = shape.transform.colorTransform;
    colorInfo.color = 0xffffff * Math.random();
    shape.transform.colorTransform = colorInfo;

    shape.velX = Math.random()*10-5
    shape.velY = Math.random()*10-5

    shape.posX = shape.x = Math.random() * stage.stageWidth;
    shape.posY = shape.y = Math.random() * stage.stageHeight;
    addChild(shape);

    shape.addEventListener(Event.ENTER_FRAME, animateShapes);
    }

    function animateShapes(evt:Event):void
    {
    var s:MovieClip = MovieClip(evt.currentTarget);
    shape.posX += shape.velX;
    shape.posY += shape.velY;

    if(shape.y <= stage.stageHeight-shape.length/2){
    shape.posY -= shape.velY;}
    if(shape.x <= stage.stageWidth-shape.width/2){
    shape.posX -= shape.velX;}
    shape.x = shape.posX;
    shape.y = shape.posY;
    }
    Last edited by Leftyplayer; 09-10-2009 at 04:13 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center