找不到文件AS3

时间:2012-03-19 15:44:31

标签: actionscript-3 flash linkage

我在AS3写一个程序。这里的确切内容似乎并不重要。我基本上有4个类,分为4个文件。事实是,它找不到其中一个文件,我无法理解为什么。我已经多次检查过,甚至让老师检查过,我们仍然无法找到它的问题。有没有其他人有类似的问题,或者对如何解决这个问题有任何想法?

编辑: 第37行1046:未找到类型或不是编译时常量:CustomTextField。 第37行1180:调用可能未定义的方法CustomTextField。 (两次)

package
{
    // Import stuff
    import flash.display.MovieClip;
    import flash.text.TextField;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.utils.*;

public class CustomButton extends MovieClip
{
    // Private variables:

    private var animationsListAR_:Array = [];// Array for the animations.
    private var textArea_:CustomTextField = new CustomTextField();
    private var curState_:int = 1;// The current state (1 = Normal, 2 = Pressed, 3 = Over).
    private var active_:Boolean;
    private var type_:String;// Multi choice, single choice, normal.
    private var group_:int;
    private var animated_:Boolean = false;

    // Protected variables:
    // Public variables:

    // Constructor:
    // This constructor sets up the event listeners and the button's properties.
    public function CustomButton( animationAR:Array, buttonlabel:String = "Hello", animated:Boolean = false, active:Boolean = true, type:String = "free", group:int = 0 )
    {
        this.gotoAndStop( curState_ );

        // Prevents the start of the animations.

        // Deals with the text inside the button.
        this.buttonMode = true;
        active_ = active;
        this.addChild( textArea_ );


        if (animated == true)
        {
            animated_ = true;
            /*
            animationsListAR_[0] = 1;

            for (var i:int = 1; i < animationAR.length; i++)
            {
            animationsListAR_[i] = animationAR[i - 1];
            }
            */
        }

        // If active_ is true the game will add EventListeners to this object.
        if (active_ == true)
        {
            this.addEventListener(MouseEvent.MOUSE_DOWN,mouseOverHandler);
            this.addEventListener(MouseEvent.MOUSE_OVER,mouseOverHandler);
            this.addEventListener(MouseEvent.MOUSE_OUT,mouseOutHandler);
        }

        // Needed to monitor the active_ var.
        this.addEventListener(Event.CHANGE, activeChangeHandler);
    }

    // This function swaps the active_ variable value and calls activeChangeHandler.
    public function ActiveChange()
    {
        active_ = ! active_;
        this.dispatchEvent(new Event(Event.CHANGE));
    }

    public function mouseOverHandler( evt:MouseEvent )
    {
        if(evt.type == MouseEvent.MOUSE_DOWN)
        {
            curState_ = 2;

            if (animated_ == true)
            {
                loopSegment( ( animationsListAR_[1] + 1 ), animationsListAR_[2] );
            }
            else
            {
                this.gotoAndStop( curState_ );
            }

            this.addEventListener( MouseEvent.MOUSE_UP, function( evt:MouseEvent ):void
                                  {
                                      evt.target.removeEventListener( MouseEvent.MOUSE_DOWN, arguments.callee );
                                      curState_ = 3;
                                      evt.target.gotoAndStop( curState_ );
                                  });
        }

        else if( evt.buttonDown != true )
        {
            curState_ = 3;

            if (animated_ == true)
            {
                loopSegment( ( animationsListAR_[2] + 1 ), animationsListAR_[3] );
            }
            else
            {
                this.gotoAndStop( curState_ );
            }
        }

        dispatchEvent(new CustomButtonEvent(CustomButtonEvent.OVER));
    }

    public function mouseOutHandler(evt:MouseEvent)
    {
        curState_ = 1;

        if (animated_ == true)
        {
            loopSegment( ( animationsListAR_[0] ), animationsListAR_[1] );
        }
        else
        {
            this.gotoAndStop( curState_ );
        }

        dispatchEvent(new CustomButtonEvent(CustomButtonEvent.OUT));
    }

    public function activeChangeHandler(evt:Event)
    {
        if (active_ == true)
        {
            this.addEventListener(MouseEvent.CLICK,mouseOverHandler);
            this.addEventListener(MouseEvent.MOUSE_OVER,mouseOverHandler);
            this.addEventListener(MouseEvent.MOUSE_OUT,mouseOutHandler);
        }
        else
        {
            this.removeEventListener(MouseEvent.CLICK,mouseOverHandler);
            this.removeEventListener(MouseEvent.MOUSE_OVER,mouseOverHandler);
            this.removeEventListener(MouseEvent.MOUSE_OUT,mouseOutHandler);
        }

        // modifyMaskButton();
    }

    /*
    public function modifyMaskButton():void
    {
    if (active_ = true)
    {

    }
    else
    {

    }
    }
    */
    public function playSegment( begin:int, end:int ):void
    {
        if (begin != end)
        {
            gotoAndPlay( begin );
            addEventListener(Event.ENTER_FRAME,function( evt:Event ):void
                    {
                        if( currentFrame == end )
                        {
                            stop();
                            removeEventListener(Event.ENTER_FRAME, arguments.callee);
                        }
                    });
        }
        else
        {
            this.gotoAndStop( end );
        }
    }

    // This loops continuosly an animation. Should, at least...
    public function loopSegment( begin:int, end:int ):void
    {
        if (begin != end)
        {
            gotoAndPlay( begin );
            addEventListener(Event.ENTER_FRAME,function( evt:Event ):void
                    {
                        if( currentFrame == end )
                        {
                            gotoAndPlay( begin );
                        }
                    });
        }
        else
        {
            this.gotoAndStop( end );
        }
    }
}
}

第二档:

package
{
import flash.display.MovieClip;
import flash.text.TextField;

public class CustomTextField extends MovieClip
{
    private var textArea:TextField;
    private var boldText:TextFormat = new TextFormat();

    function CustomTextField()
    {
        textArea = new TextField;
    }

    override function CustomTextfield( labelText:String, font:String = "Arial", color:uint = 0xFFFFFFFF, size:uint = 10 )
    {
        textArea = new TextField;
        boldText.font = font;
        boldText.color = color;
        boldText.size = size;
        this.text = labelText;
    }

    function changeFont( font:String ):void
    {
        boldText.font = font;
        updateText();
    }

    function changeColor( color:uint ):void
    {
        boldText.color = color;
        updateText();
    }

    function changeSize( size:uint ):void
    {
        boldText.size = size;
        updateText();
    }

    function embedText( choice:Boolean ):void
    {
        this.embedFonts = choice;
    }

    function updateText():void
    {
        this.setTextFormat( boldText );
    }
}
}

1 个答案:

答案 0 :(得分:1)

在第二个文件中检查此行:

 override function CustomTextfield( labelText:String, font:String = "Arial"

“CustomTextfield”//应为“CustomTextField”,在您的脚本中缺少大写字母。

我认为你得到2个错误,因为这个函数在脚本中被触发两次或者一些相关的更改它让我们知道。