2013-05-15 33 views
0

我試圖用這段代碼實現的目標是,如果一個剪輯在它顯示後被鎖定,它應該播放。如果週一的選擇是針對它應該播放星期一剪輯。但代碼不起作用。錯誤是這樣的:目標事件問題

Scene 1, Layer 'Layer 1', Frame 2, Line 75 1120: Access of undefined property play_event. 
Scene 1, Layer 'Layer 1', Frame 2, Line 74 1120: Access of undefined property play_event. 


var week_pick:Weekday_Choice = new Weekday_Choice(); 
var weekdayArray: Array = new Array(); 
var monday:Mon_D_but = new Mon_D_but(); 
var tuesday:Tues_D_but = new Tues_D_but(); 
var wednesday:Wed_D_but = new Wed_D_but(); 
var thursday:Thurs_D_but = new Thurs_D_but(); 
var friday:Fri_D_but = new Fri_D_but(); 
var choice_play: Array = new Array(); 

choice_play.push(monday, tuesday, wednesday, thursday, friday); 

addChild(week_pick); 

choice_play[0].x = 73.1; 
choice_play[0].y = 316.75; 

choice_play[1].x = 251.9; 
choice_play[1].y = 278.35; 

choice_play[2].x = 399.95; 
choice_play[2].y = 375.85; 

choice_play[3].x = 345.2; 
choice_play[3].y = 602.4; 

choice_play[4].x = 80.15; 
choice_play[4].y = 603.05; 

week_pick.addEventListener(Event.ENTER_FRAME, moveon); 

function moveon(event:Event) 
{ 
    if (week_pick.currentFrame == 103) 
    { 

     week_pick.stop(); 
     for (var a = 0; a < choice_play.length; a++) 
     { 
      addChild(choice_play [a]); 
      choice_play[a].alpha = 0; 
      choice_play[a].stop(); 
     } 

     this.addEventListener(MouseEvent.CLICK,choice_play_ev); 


    } 
} 

function choice_play_ev(play_event: MouseEvent) 
{ 

    if (play_event.target != week_pick) 
    { 

     play_event.target.alpha = 1; 

     play_event.target.addEventListener(Event.ENTER_FRAME, play_target,false,0,true); 

    } 

} 
function play_target(e:Event) 
{ 

    play_event.target.play(); 
    if (play_event.target.currentFrame == 15) 
    { 
     destroyall_2(); 
    } 

} 

我不完全確定,如果我這樣做是正確的。屏幕上只有真正的2列物品,開始時不需要任何交互的初始影片剪輯,以及點擊時需要播放的剪輯。有人能幫我解決嗎?

+1

在你的'play_target'方法中,'play_event'不是一個參數,類變量或局部變量,所以它是未定義的。因此你不能播放它,或者檢查它的currentFrame。您應該檢查調試器,以便確定錯誤。如果它說「未定義的財產」,那就意味着這一點。 – prototypical

+0

啊哈我明白了。我非常努力地工作。 – tailedmouse

回答

1

play_target中,您試圖訪問play_event這是未定義的。你在這種情況下的事件是e

+0

哦,我看到這樣的事件不會傳遞。非常感謝它開始工作的答案。 – tailedmouse

+0

不,它通過了。否則,你會得到一個隱式強制錯誤。問題在於你正在引用一個不存在的變量。 –