2014-03-12 78 views
0

基本上我有这个AS3代码试图想出两个信息文本,但一个不滚动我在这里做错了什么?有posiblle来解决这个问题吗?或者我在做vrog功能重复。下面是代码:AS3 Flash文本不滚动

//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; 
    } 
} 
} 

回答

0

不正确的,实际上你应该在编译时出现错误,您有重复的处理程序的声明。

//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; 
    } 
} 
+0

尼古拉斯你真的很擅长AS3再次谢谢你 – user3391599