简体   繁体   中英

AS3 flash text is not scrolling

Basicly i have this AS3 code trying to come up with two info texts but one is not scrolling what did i do wrong here? Is posiblle to resolve this? Or am i doing vrog function duplication. Here is the code:

//SCROLLING SPEED
var scrolling_speed:int = 2;
var scrolling_speed2:int = 4;

//TEXT TO SCROLL
var text_to_scroll:String = "This text is scrolling fine.";  
var text2_to_scroll:String = "This text doesnt scroll.";


//establish the field
var my_text:TextField = new TextField();
var my_text2:TextField = new TextField();
//add the field to stage
addChild(my_text);
addChild(my_text2);
//set the text
my_text.text = text_to_scroll;
my_text2.text = text2_to_scroll;
//set the x coord off right side of stage
my_text.x = stage.stageWidth;
my_text2.x = stage.stageWidth;
//set y coord in middle of stage (about)
my_text.y = (stage.stageHeight/1)-(my_text.height/2.5);
my_text2.y = (stage.stageHeight/1)-(my_text2.height/2);
//not selectable
my_text.selectable = false;
my_text2.selectable = false;
//no border
my_text.border = false;
my_text2.border = false;
//field scales with more text
my_text.autoSize = TextFieldAutoSize.LEFT;
my_text2.autoSize = TextFieldAutoSize.LEFT;

//set a format
var my_text_format:TextFormat = new TextFormat();
var my_text2_format:TextFormat = new TextFormat();
//set the color to the hex
my_text_format.color = 0x000000;
my_text2_format.color = 0x000000;
//set the font size
my_text_format.size = 28;
my_text2_format.size = 18;
//set the font face
my_text_format.font = "Futura Md BT";
my_text2_format.font = "Futura Md BT";
//apply formatting
my_text.defaultTextFormat = my_text_format;
my_text.setTextFormat(my_text_format);
my_text2.defaultTextFormat = my_text2_format;
my_text2.setTextFormat(my_text2_format);

//add the listener to scroll
my_text.addEventListener(Event.ENTER_FRAME,move_text);
my_text2.addEventListener(Event.ENTER_FRAME,move_text);

//scroll function
function move_text(myevent:Event):void {
    my_text.x-=scrolling_speed;
    if(my_text.x<(0-my_text.width)){
        my_text.x=stage.stageWidth;

        }
function move_text(myevent:Event):void {        
        my_text2.x-=scrolling_speed2;
    if(my_text2.x<(0-my_text2.width)){
        my_text2.x=stage.stageWidth;
    }
}
}

Incorrect, actually you should get error at compile time, you have duplicate in declarations of handler.

//add the listener to scroll
addEventListener(Event.ENTER_FRAME, onMoveTexts);

//scroll function
function onMoveTexts(e:Event):void {
    my_text.x-=scrolling_speed;
    my_text2.x-=scrolling_speed2;
    if(my_text.x<-my_text.width){
        my_text.x=stage.stageWidth;
    }

    if(my_text2.x<-my_text2.width){
        my_text2.x=stage.stageWidth;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM