A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: AS3 MC Animation

  1. #1
    Senior Member
    Join Date
    Jun 2001
    Posts
    250

    AS3 MC Animation

    Hello,

    I'm trying to animate a mc on stage. If I use the code shown below directly on the main timeline the code executes flawlessly. However, when attempting to place the code in a Class file and invoke from the timeline nothing happens?

    I thought the code contained all the basic class and movieclip components;


    //--- invoke from timeline----
    var myClass = new fClass2();//invoke traces ok.
    myClass.fClass(); //traces ok
    myClass.mfease(); //nothing wrong ???


    //---- class code -----
    package {
    import flash.display.*;
    import flash.events.*;
    public class fClass2 extends MovieClip{

    public function fClass() {
    // constructor code
    trace("from conctructor");
    }

    public function mfease():void{
    trace("from mfease");


    var a:Number = 0;
    var speed:Number = 10;
    var distance:Number = 200;

    this.addEventListener(Event.ENTER_FRAME,fease);
    function fease(event:Event){
    a=(distance-ioc1.x)/speed;
    ioc1.x+=a;
    addChild(ioc1);
    }



    }

    }
    }


    Any help will be appreciated.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Please use [code] tags.

    The thing you have labeled the constructor is not the constructor, because it has a different name than the class.

    It doesn't do anything anyway, though.

    You never added your fClass2 instance to the displaylist, so I'm not sure whether it will ever dispatch an ENTER_FRAME event to trigger fease.

    Even if it does, ioc1 is undefined in fClass2. And even if it were defined, adding the same instance every frame will do nothing but bring that same instance to the top of the fClass2's children. If you wanted to put a bunch of copies of ioc1 (whatever it is) on the display, you'll need to create new instances.

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