我正在用 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 );
}
}
}