actionscript-3flashadobeflash-cs6flash-cc

scrolling text field help as3


Currently got text off stage that I would like to come onto the stage and stop at a certain position (97, 233.10) on my stage. I'm a little confused on where to stop it and what code to use?

addEventListener(Event.ENTER_FRAME, mcInfo);

 function mcInfo (e:Event):void {

//check position of logo
//if inside the stage move left to right
//if outside stage reposition

if (info.x<stage.stageWidth) {
    info.x+=30;
    stop();
    } else {
        //reset position
        info.x=-450;
    }
}

Cheers!

It also seems that Flash is now returning an output error when I scroll through the rest of my pages:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at finaldesign_fla::MainTimeline/mcInfo()

Solution

  • In the if statement we check if the object has exceeded the target position and stop the loop if it has. Otherwise keep incrementing the object's position.

    targetPosition = {x:97, y:233.10};
    
    addEventListener(Event.ENTER_FRAME, mcInfo);
    
    function mcInfo(e:Event) {
       if (info.x >= targetPosition.x) {
          info.x = targetPosition.x;
          removeEventListener(Event.ENTER_FRAME, mcInfo);
       } else {
          info.x += 30;
       }
    }