2011-10-26 83 views
0

如何使用AS3的加載程序類將圖像加載到具有事件處理程序的按鈕中?以下是我開始的。以下是我點擊郵件時遇到的錯誤。使用加載程序添加圖像,並使用事件處理程序生成圖像按鈕

AS:

//call function that starts loading my image 
callButtons(); 


function callButtons():void {  
     var spanish_url = root_path + "spanish.png"; 
     var spanish_loader = new Loader(); 
     spanish_loader.load (new URLRequest(spanish_url)); 

//on load complete call the spanishLoaded function 

     spanish_loader.contentLoaderInfo.addEventListener (Event.COMPLETE, spanishLoaded); 
} 


//add loaded image to my main_container set x,y and turn it into a button. 

    function spanishLoaded (e:Event):void { 
     var my_spanish:Loader = Loader(e.target.loader);  
     my_spanish.x = 1062; 
     my_spanish.y = 620; 
     main_container.addChild(my_spanish); 
     my_spanish.addEventListener (MouseEvent.CLICK, playSpanish); 
    } 

function playSpanish(){ 

     trace("IN SPANISH"); 
} 

當我點擊舞臺上的spanish.png我得到的錯誤是:ArgumentError: Error #1063: Argument count mismatch on MyVideoPlayer_CS4_fla::MainTimeline/playSpanish(). Expected 0, got 1.

我需要爲Added EVT:的MouseEvent

回答

1

在你的函數spanishLoaded你添加一個事件監聽器:

my_spanish.addEventListener (MouseEvent.CLICK, playSpanish); 

playSpanish功能會想到鼠標事件:

您有:

function playSpanish() 

這應該是:

function playSpanish (event:MouseEvent) 
相關問題