2011-03-18 59 views
0

我正在爲Blackberry Playbook開發ActionScript 3.0應用程序。等待,直到兩個圖像之間的轉換完成

我有12個加載了Loader類的圖像。我用Event.ENTER_FRAME褪色的方法,使用此事件處理淡出圖片:

private function onEnterFrame(event:Event):void 
{ 
    imageToFront.alpha += 0.1; // slow fade 
    imageToBack.alpha -= 0.1; 

    if(imageToFront.alpha >= 1.0) 
    { 
     imageToFront.alpha = 1.0; 

     // hide the first image 
     imageToBack.alpha = 0.0; 
     imageToBack.visible = false; 

     // remove the enter frame event listener 
     stage.removeEventListener(Event.ENTER_FRAME, onEnterFrame); 
    } 
} 

當圖像的用戶點擊它拋出以下click處理程序:我有以下問題

private function onImageClicked(event:MouseEvent):void 
{ 
    switch((event.currentTarget as Loader).name) 
    { 
     case imageCell11Back.name: 
      imageToFront = imageCell11Front; 
      imageToBack = imageCell11Back; 
      break; 
     case imageCell11Front.name: 
      imageToFront = imageCell11Back; 
      imageToBack = imageCell11Front; 
      break; 
     case imageCell12Back.name: 
      imageToFront = imageCell12Front; 
      imageToBack = imageCell12Back; 
      break; 
     case imageCell12Front.name: 
      imageToFront = imageCell12Back; 
      imageToBack = imageCell12Front; 
      break; 
     case imageCell13Back.name: 
      imageToFront = imageCell13Front; 
      imageToBack = imageCell13Back; 
      break; 
     case imageCell13Front.name: 
      imageToFront = imageCell13Back; 
      imageToBack = imageCell13Front; 
      break; 
     case imageCell21Back.name: 
      imageToFront = imageCell21Front; 
      imageToBack = imageCell21Back; 
      break; 
     case imageCell21Front.name: 
      imageToFront = imageCell21Back; 
      imageToBack = imageCell21Front; 
      break; 
     case imageCell22Back.name: 
      imageToFront = imageCell22Front; 
      imageToBack = imageCell22Back; 
      break; 
     case imageCell22Front.name: 
      imageToFront = imageCell22Back; 
      imageToBack = imageCell22Front; 
      break; 
     case imageCell23Back.name: 
      imageToFront = imageCell23Front; 
      imageToBack = imageCell23Back; 
      break; 
     case imageCell23Front.name: 
      imageToFront = imageCell23Back; 
      imageToBack = imageCell23Front; 
      break; 
    } 
    stage.addEventListener(Event.ENTER_FRAME, onEnterFrame); 
    imageToFront.visible = true; 
} 

如果用戶在上一張圖片尚未達到alpha = 1.0之前點擊另一張圖片,則該圖片的alpha值會小於1.0。

換句話說,我不得不讓onEnterFrame功能設置alpha爲1.0。

任何想法?我試過stage.hasEventListener(Event.ENTER_FRAME)但它不起作用。

回答

0

我的解決辦法:

private function onEnterFrame(event:Event):void 
{ 
    imageToFront.alpha += 0.1; // slow fade 
    imageToBack.alpha -= 0.1; 

    if(imageToFront.alpha >= 1.0) 
    { 
     imageToFront.alpha = 1.0; 

     // hide the first image 
     imageToBack.alpha = 0.0; 
     imageToBack.visible = false; 

     // remove the enter frame event listener 
     stage.removeEventListener(Event.ENTER_FRAME, onEnterFrame); 
     faddingCard = false; 
    } 
} 

當圖像的用戶點擊它拋出以下點擊處理程序:

private function onImageClicked(event:MouseEvent):void 
{ 
    if (faddingCard) return; 

    switch((event.currentTarget as Loader).name) 
    { 
     case imageCell11Back.name: 
      imageToFront = imageCell11Front; 
      imageToBack = imageCell11Back; 
      break; 
     case imageCell11Front.name: 
      imageToFront = imageCell11Back; 
      imageToBack = imageCell11Front; 
      break; 
     case imageCell12Back.name: 
      imageToFront = imageCell12Front; 
      imageToBack = imageCell12Back; 
      break; 
     case imageCell12Front.name: 
      imageToFront = imageCell12Back; 
      imageToBack = imageCell12Front; 
      break; 
     case imageCell13Back.name: 
      imageToFront = imageCell13Front; 
      imageToBack = imageCell13Back; 
      break; 
     case imageCell13Front.name: 
      imageToFront = imageCell13Back; 
      imageToBack = imageCell13Front; 
      break; 
     case imageCell21Back.name: 
      imageToFront = imageCell21Front; 
      imageToBack = imageCell21Back; 
      break; 
     case imageCell21Front.name: 
      imageToFront = imageCell21Back; 
      imageToBack = imageCell21Front; 
      break; 
     case imageCell22Back.name: 
      imageToFront = imageCell22Front; 
      imageToBack = imageCell22Back; 
      break; 
     case imageCell22Front.name: 
      imageToFront = imageCell22Back; 
      imageToBack = imageCell22Front; 
      break; 
     case imageCell23Back.name: 
      imageToFront = imageCell23Front; 
      imageToBack = imageCell23Back; 
      break; 
     case imageCell23Front.name: 
      imageToFront = imageCell23Back; 
      imageToBack = imageCell23Front; 
      break; 
    } 
    faddingCard = true; 
    stage.addEventListener(Event.ENTER_FRAME, onEnterFrame); 
    imageToFront.visible = true; 
} 

我添加了一個faddingCard Boolean類變量時onImageClick被拋出來控制。

0

嘗試設置事件偵聽器的imageToFront也是一個在imageToBack這樣的:


imageToFront.removeEventListener(Event.ENTER_FRAME, fadeIn); 
imageToFront.addEventListener(Event.ENTER_FRAME, fadeIn); 

imageToBack.removeEventListener(Event.ENTER_FRAME, fadeOut); 
imageToBack.addEventListener(Event.ENTER_FRAME, fadeOut); 

淡入淡出功能應該像到:


private function fadeIn(event : Event) : void { 
    var currentLoader : Loader = event.target as Loader; 
    currentLoader.alpha += .1; 

    if(currentLoader.alpha >= 1) { 
     currentLoader.removeEventListener(Event.ENTER_FRAME, fadeIn); 
    } 
} 

private function fadeOut(event : Event) : void { 
    var currentLoader : Loader = event.target as Loader; 
    currentLoader.alpha -= .1; 

    if(currentLoader.alpha (inf)= 0) { 
     currentLoader.visible = false; 
     currentLoader.removeEventListener(Event.ENTER_FRAME, fadeOut); 
    } 
} 

**代替(INF)由< **我不知道爲什麼它被截斷,如果我設置它...

對於補間值,你應該看看不同的補間引擎,如​​。

+0

我有同樣的問題,如果我點擊一個圖像使淡出,然後我點擊另一個圖像,使其淡出。 – VansFannel 2011-03-18 16:20:28

相關問題