Actionscript 3.0 Simple Scrolling Marquee

I don’t know if anyone else has been having any troubles with this, and sense I hadn’t done one before I decided to make this simple one. I noticed there isn’t really any actionscript 3.0 versions of a marquee out there but… this might help some people to get going.

  1. first thing is you would want to put in 2 items: 1 a simple button, and 2 a dynamic text field.

  2. give your button a instance name of togglebtn

  3. give your dynamic text field a instance name of display_txt

  4. make sure you dont have either the button or the text field selected and insert the following code into layer1 frame 1:


var intervalID:int;

display_txt.text = "hello world.  how are you today? will this work or not?" + "             ";

function scrollText() {
    // default step will be 1
    var tempstring,tempstr:String;
    tempstring = display_txt.text;
    tempstr = tempstring.substr(1, tempstring.length) +    tempstring.substr(0,1);
    display_txt.text = tempstr;
}
function togglescroll(e:Event):void {
    if (intervalID != 0) {
        clearInterval(intervalID);
        intervalID = 0;
    } else {
        intervalID = setInterval(scrollText, 200);
    }
}

togglebtn.addEventListener(MouseEvent.CLICK, togglescroll);

this is a very basic marquee but I’m sure others can improve it. if you did everything right (which isn’t too tough) you should be able to click the button to start and stop the marquee from scrolling.

If your going to swap the marquee message, you will need to toggle the scrolling off change the text, then toggle the scroll back on, else you may end up with undesireable results.