不同图层和不同框架的文本框中的文本

时间:2014-07-24 13:28:08

标签: actionscript-3 flash class layer

我是编程新手;特别是面向对象的编程,现在已经有一段时间了。

我有一个.fla文件;第1帧是容器。如果单击它,则会显示另外三个帧(第1层)。第1层的第2帧是正确的动画;第3帧是不正确的。在第2帧(我认为第2层)是一个动态的textField。这是我想要我的_correctText去的地方(_incorrectText需要进入第3帧(第2层)。注意:我已经能够动态添加文本但我需要一个实际的文本框,我们的图形艺术家可以"触摸&# 34;所以这种技术是禁止的。

我觉得我需要"冒泡",添加听众,并做显示,但我无法弄清楚如何实现它。

时间线上没有代码可以存在;我们的想法是"组件化"这个;因此,可检查者。

非常感谢任何帮助,如果你可以愚蠢的"这个术语很棒......

这是我的代码:

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 个答案:

答案 0 :(得分: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;

    }

}
}