编程新手;特别是面向对象的编程,并且已经在这方面工作了一段时间了。
我有一个。fla文件;帧1是容器。如果你点击它,会显示另外三帧(第一层)。第一层的第二帧是正确的动画;第三帧是不正确的。在第2帧(第2层,我认为)是一个动态textField。这就是我想要我的_correctText的位置(_incorrectText需要在第3帧(第2层)。注意:我已经能够动态添加文本,但我需要一个实际的文本框,我们的图形艺术家可以"触摸",所以技术是不允许的。
我觉得我需要"冒泡",添加监听器,并做显示,但我不知道如何实现。
没有代码可以在时间轴上存在;我们的想法是将其"组件化";
任何帮助都是非常感谢的,如果你能"简化"术语,那将是很棒的…
下面是我的代码: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
}
}
}
答案如下:
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;
}
}
}