2014-07-24 35 views
0

我是編程新手;特別是面向對象的編程,並且一直在研究這一點。不同層和不同幀的文本框中的文本

我有一個.fla文件;框架1是容器。如果點擊它,則會顯示另外三個框架(第1層)。第1層的第2幀是正確的動畫;第3幀是不正確的。在第2幀(我認爲第2層)是一個動態文本字段。這是我希望我的_correctText去的地方(_incorrectText需要在第3幀(第2層)上注意:我已經能夠動態地添加文本,但我需要一個實際的文本框,我們的圖形藝術家可以「觸摸」是一個沒有去。

我覺得我需要「冒泡」,增加聽衆,做顯示器,但我無法弄清楚如何實現這一點。

沒有代碼可以住在時間軸上;這個想法是「組件化」這個。因此,inspectables

任何幫助是極大的讚賞,如果你可以「啞下」的術語,這將是真棒......

這裏是我的代碼:

package 
{ 
    import flash.display.MovieClip; 
    import flash.events.MouseEvent; 
    import flash.events.Event; 
    import flash.display.DisplayObject; 
    import flash.display.FrameLabel; 
    import flash.display.SimpleButton; 
    import flash.text.* 

public dynamic class hotSpotContainer extends MovieClip 
    { 
     var _incorrectText:String = ""; 
     var _correctText:String = ""; 

     public function hotSpotContainer() 
     { 
      stop(); 
      addEventListener (Event.EXIT_FRAME, onExitFrame); 
     } 

     protected function onExitFrame($event:Event):void 
     { 
      removeEventListener(Event.EXIT_FRAME, onExitFrame); 
      ButtonClicks(); 
     } 

     public function ButtonClicks() 
     /*If the mouse is clicked on one of the buttons listed below, go to the appropriate function.*/ 
     { 
      (this as MovieClip).correct_Btn.addEventListener(MouseEvent.CLICK, correctAnimation); 
      (this as MovieClip).incorrect_Btn.addEventListener(MouseEvent.CLICK, incorrectAnimation); 
     } 

     public function correctAnimation($event:MouseEvent) 
     /*If the correct_Btn is clicked, go to the correctScreen frame and stop. 
     The correctScreen frame includes the correct animation (Correct_anim) which tweens to a correct screen.*/ 
     { 
      gotoAndStop("correctScreen"); 
      (this as MovieClip).reset_Btn.addEventListener(MouseEvent.CLICK, resetImage); 
     } 

     public function incorrectAnimation($event:MouseEvent) 
     /*If the incorrect_Btn is clicked, go to the incorrectScreen frame and stop. 
     The incorrectScreen frame includes the incorrect animiation (Incorrect_anim) which tweens to an incorrect screen.*/ 
     { 
      gotoAndStop("incorrectScreen"); 
      (this as MovieClip).reset_Btn.addEventListener(MouseEvent.CLICK, resetImage);   
     } 

     public function resetImage($event:MouseEvent) 
     /*If the reset_Btn is clicked, go to the startPoint frame and stop. 
     The startPoint frame brings the user back to the beginning. Reinvoking ButtonClicks allows the user to start over.*/ 
     { 
      gotoAndStop("startPoint"); 
      ButtonClicks(); 
     } 

     [Inspectable(name = "01) Incorrect Message Text: ", type = "String", defaultValue = "")] 
     /*Creates a parameter field in which to type the incorrect answer message.*/ 

     public function set incorrectTextBox ($value:String):void 
     /*Puts the incorrect answer message in the incorrect text box.*/ 
     { 
      _incorrectText = $value; 
     } 

     [Inspectable(name = "02) Correct Message Text: ", type = "String", defaultValue = "")] 
     /*Creates a parameter field in which to type the correct answer message.*/ 

     public function set correctTextBox ($value:String):void 
     /*Puts the correct answer message in the correct text box.*/ 
     { 
      _correctText = $value; 
//   correctTxtBox.text = _correctText 
     } 
    } 

} 

回答

1

下面是答案:

package 
{ 
    import flash.display.MovieClip; 
    import flash.events.MouseEvent; 
    import flash.events.Event; 
    import flash.display.DisplayObject; 
    import flash.display.FrameLabel; 
    import flash.display.SimpleButton; 
    import flash.text.* 
public class hotSpotContainer extends MovieClip 
{ 
    var _incorrectText:String = ""; 
    var _correctText:String = ""; 

    public function hotSpotContainer() 
    { 
     stop(); 

     addEventListener(Event.EXIT_FRAME, onExitFrame); 
    } 

    protected function onExitFrame($event:Event):void 
    { 
     removeEventListener(Event.EXIT_FRAME, onExitFrame); 
     ButtonClicks(); 
    } 

    /*If the mouse is clicked on one of the buttons listed below, go to the appropriate function.*/ 

    protected function ButtonClicks() 
    { 
     (this as MovieClip).correct_Btn.addEventListener(MouseEvent.CLICK, correctAnimation); 
     (this as MovieClip).incorrect_Btn.addEventListener(MouseEvent.CLICK, incorrectAnimation); 
    } 

    /* If the correct_Btn is clicked, go to the correctScreen frame and stop. 
    The correctScreen frame includes the correct animation (Correct_anim) which tweens to a correct screen.*/ 

    public function correctAnimation($event:MouseEvent) 
    { 
     gotoAndStop("correctScreen"); 

     (this as MovieClip).correct_mc.setResponseText(_correctText); 

     (this as MovieClip).response_txt.text = _correctText; 

     (this as MovieClip).reset_Btn.addEventListener(MouseEvent.CLICK, resetImage); 
    } 

    /* If the incorrect_Btn is clicked, go to the incorrectScreen frame and stop. 
    The incorrectScreen frame includes the incorrect animiation (Incorrect_anim) which tweens to an incorrect screen.*/ 

    public function incorrectAnimation($event:MouseEvent) 
    { 
     gotoAndStop("incorrectScreen"); 

     (this as MovieClip).incorrect_mc.setResponseText(_incorrectText); 

     (this as MovieClip).response_txt.text = _incorrectText; 

     (this as MovieClip).reset_Btn.addEventListener(MouseEvent.CLICK, resetImage); 
    } 

    /*If the reset_Btn is clicked, go to the startPoint frame and stop. 
    The startPoint frame brings the user back to the beginning. Reinvoking ButtonClicks allows the user to start over.*/ 

    public function resetImage($event:MouseEvent) 
    { 
     gotoAndStop("startPoint"); 
     ButtonClicks(); 
    } 

    [Inspectable(name = "01) Incorrect Message Text: ", type = "String", defaultValue = "")] 
    public function set incorrectTextBox ($value:String):void 
    { 
     _incorrectText = $value; 
    } 

    [Inspectable(name = "02) Correct Message Text: ", type = "String", defaultValue = "")]  
    public function set correctTextBox ($value:String):void 
    { 
     _correctText = $value; 
    } 
} 

}

而且,其他類:

package 
{ 
    import flash.display.MovieClip; 
    import flash.events.Event; 


public class ResponseAnimation extends MovieClip 
{ 
    protected var _responseText:String = ""; 

    public function ResponseAnimation() 
    { 

    } 

    public function setResponseText($value:String):void 
    { 

     var response:String = $value; 

     (this as MovieClip).beginning_mc.response_txt.multiline = true; 
     (this as MovieClip).beginning_mc.response_txt.wordWrap = true; 
     (this as MovieClip).beginning_mc.response_txt.text = response; 

     this.visible = true; 

    } 

} 
} 
相關問題