2012-03-19 50 views
-1

我正在寫一個程序在AS3。這裏確切的內容似乎並不重要。我基本上有4個班,分成4個檔案。事情是,它無法找到這些文件之一,我不明白爲什麼。我已經多次檢查過,甚至讓我的老師檢查過它,但我們仍然無法找到問題所在。有沒有其他人有類似的問題,或有任何想法如何解決這個問題?文件未找到AS3

編輯: 行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

你不能指望得到一個問題的答案,只是說你有問題。給我們提供錯誤消息,項目結構和/或源代碼本身的描述。試着用易於理解的東西來分解你的問題。 – devsnd 2012-03-19 15:56:18

+0

@twall這不僅對我們有幫助,但經常在您分解問題時最終找到答案。 – 2012-03-19 16:01:08

+0

有人會說「啊,是的,這是一個已知的Flash問題,當你有4個文件」時,你應該進一步描述一些事情。 – Kodiak 2012-03-19 16:26:33

回答

1

入住此行的第二個文件:

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

「CustomTextfield」 //應該是 「CustomTextField」,在腳本中失蹤大寫字母。

我覺得你得到2個錯誤,因爲這個函數在腳本內被觸發兩次或者有一些相關的改變並且讓我們知道。

+0

當然它在同一個目錄中。是的,他們被正確引用。無論如何,我添加了源代碼。 – MKII 2012-03-19 20:17:08

+0

我製作了新的.as和.fla文件,然後複製並粘貼所有內容。它找到了該文件。我仍然不知道它會是什麼。無論如何,上面的這一行固定了之後出現的錯誤。 – MKII 2012-03-20 19:41:40

+0

好吧,我仍然幫助,哈哈可能是記憶體中的一個錯誤..在cs5中發生了奇怪的事情,加載的內容突然停止apearing沒有錯誤,所以我不得不重新開始像你的self.hope都很好..我投了1票:) – joshua 2012-03-21 02:18:03