我有这个小项目。每次单击按钮时更改的帧,以及箭头内的进度条模拟。
stop();
/** initializtios **/
var trans:ColorTransform = next_arrow.transform.colorTransform;
var p:int = 1;
var myColorTransform = new ColorTransform();
myColorTransform.color = 0x42f498;
var trans1:ColorTransform = back_arrow.transform.colorTransform;
/** actual code **/
btn_next_arrow.addEventListener(MouseEvent.CLICK, function goNextLectFrame(e:MouseEvent):void {
if (p==1) {
fill_1.transform.colorTransform = myColorTransform;
fill_22.alpha = 0.00001;
fill_3.alpha = 0.00001;
fill_33.alpha = 0.00001;
fill_5.alpha = 0.00001;
fill_6.alpha = 0.00001;
fill_7.alpha = 0.00001;
fill_8.alpha = 0.00001;
fill_9.alpha = 0.00001;
fill_10.alpha = 0.00001;
fill_11.alpha = 0.00001;
fill_12.alpha = 0.00001;
fill_13.alpha = 0.00001;
fill_14.alpha = 0.00001;
fill_151.alpha = 0.00001;
++p;
}
switch (currentFrame) {
case 1:
gotoAndStop(2);
break;
case 2:
fill_22.transform.colorTransform = myColorTransform;
gotoAndStop(3);
break;
case 3:
fill_3.transform.colorTransform = myColorTransform;
gotoAndStop(4);
break;
case 4:
fill_33.transform.colorTransform = myColorTransform;
gotoAndStop(5);
break;
case 5:
fill_5.transform.colorTransform = myColorTransform;
gotoAndStop(6);
break;
case 6:
fill_6.transform.colorTransform = myColorTransform;
gotoAndStop(7);
break;
case 7:
fill_7.transform.colorTransform = myColorTransform;
gotoAndStop(8);
break;
case 8:
fill_8.transform.colorTransform = myColorTransform;
gotoAndStop(9);
break;
case 9:
fill_9.transform.colorTransform = myColorTransform;
gotoAndStop(10);
break;
case 10:
fill_10.transform.colorTransform = myColorTransform;
gotoAndStop(11);
break;
case 11:
fill_11.transform.colorTransform = myColorTransform;
gotoAndStop(12);
break;
case 12:
fill_12.transform.colorTransform = myColorTransform;
gotoAndStop(13);
break;
case 13:
fill_13.transform.colorTransform = myColorTransform;
gotoAndStop(14);
break;
case 14:
fill_14.transform.colorTransform = myColorTransform;
gotoAndStop(15);
break;
case 15:
fill_151.transform.colorTransform = myColorTransform;
gotoAndStop(16);
break;
case 16:
gotoAndStop(17);
break;
}
});
btn_next_arrow.addEventListener(MouseEvent.MOUSE_OVER, function hovering(e:MouseEvent):void {
trans.color = uint(0x606266);
next_arrow.transform.colorTransform = trans;
});
btn_back_arrow.addEventListener(MouseEvent.MOUSE_OVER, function hovering1(e:MouseEvent):void {
trans1.color = uint(0x606266);
back_arrow.transform.colorTransform = trans1;
});
btn_next_arrow.addEventListener (MouseEvent.MOUSE_OUT, function hideShadow(event:MouseEvent):void {
trans.color = uint(0x999999);
next_arrow.transform.colorTransform = trans;
});
btn_back_arrow.addEventListener (MouseEvent.MOUSE_OUT, function hideShadow1(event:MouseEvent):void {
trans1.color = uint(0x999999);
back_arrow.transform.colorTransform = trans1;
});
btn_back_arrow.addEventListener(MouseEvent.CLICK, function goPrevLectFrame(e:MouseEvent):void {
switch(currentFrame){
case 2:
gotoAndStop(1);
break;
case 3:
gotoAndStop(2);
break;
case 4:
gotoAndStop(3);
break;
case 5:
gotoAndStop(4);
break;
case 6:
gotoAndStop(5);
break;
case 7:
gotoAndStop(6);
break;
case 8:
gotoAndStop(7);
break;
case 9:
gotoAndStop(8);
break;
case 10:
gotoAndStop(9);
break;
case 11:
gotoAndStop(10);
break;
case 12:
gotoAndStop(11);
break;
case 13:
gotoAndStop(12);
break;
case 14:
gotoAndStop(13);
break;
case 15:
gotoAndStop(14);
break;
case 16:
gotoAndStop(15);
break;
}
});
btn_main_menu.addEventListener(MouseEvent.CLICK, function goPrevLectFrame1(e:MouseEvent):void {
gotoAndStop(17);
});
问题是,当我到达最后一帧并单击下一个按钮时,它说:
TypeError:错误#1009:...“null”。在 函数/()[RECOVER_shitty_fla.MainTimeline ::帧1:114]
这是导致功能的问题:
btn_next_arrow.addEventListener (MouseEvent.MOUSE_OUT, function hideShadow(event:MouseEvent):void {
trans.color = uint(0x999999);
next_arrow.transform.colorTransform = trans; // LINE 114
});
我真的在这里挣扎,会感激任何帮助,谢谢你。
答案 0 :(得分:2)
您需要在进入最终帧之前删除事件侦听器。您的程序仍然在该帧上不存在的对象上侦听MouseEvent
。
另外,我注意到了@ BadFeelingAbout这个建议。 内联函数是不好的做法,通常应该避免使用。
此代码还存在其他问题(主要是次要问题)。我已经从FLA文档中调整了代码以使程序正常工作。 请参阅以下更改。
stop();
import flash.events.MouseEvent;
import flash.system.fscommand;
import flash.display.StageScaleMode;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.geom.ColorTransform;
/** initializtios **/
var trans:ColorTransform = next_arrow.transform.colorTransform;
var p:int = 1;
var myColorTransform = new ColorTransform();
myColorTransform.color = 0x42f498;
var trans1:ColorTransform = back_arrow.transform.colorTransform;
/** actual code **/
btn_next_arrow.addEventListener(MouseEvent.CLICK, goNextLectFrame);
function goNextLectFrame(e:MouseEvent):void {
if (p==1) {
fill_1.transform.colorTransform = myColorTransform;
fill_22.alpha = 0.00001;
fill_3.alpha = 0.00001;
fill_33.alpha = 0.00001;
fill_5.alpha = 0.00001;
fill_6.alpha = 0.00001;
fill_7.alpha = 0.00001;
fill_8.alpha = 0.00001;
fill_9.alpha = 0.00001;
fill_10.alpha = 0.00001;
fill_11.alpha = 0.00001;
fill_12.alpha = 0.00001;
fill_13.alpha = 0.00001;
fill_14.alpha = 0.00001;
fill_151.alpha = 0.00001;
++p;
}
switch (currentFrame) {
case 1:
gotoAndStop(2);
break;
case 2:
fill_22.transform.colorTransform = myColorTransform;
gotoAndStop(3);
break;
case 3:
fill_3.transform.colorTransform = myColorTransform;
gotoAndStop(4);
break;
case 4:
fill_33.transform.colorTransform = myColorTransform;
gotoAndStop(5);
break;
case 5:
fill_5.transform.colorTransform = myColorTransform;
gotoAndStop(6);
break;
case 6:
fill_6.transform.colorTransform = myColorTransform;
gotoAndStop(7);
break;
case 7:
fill_7.transform.colorTransform = myColorTransform;
gotoAndStop(8);
break;
case 8:
fill_8.transform.colorTransform = myColorTransform;
gotoAndStop(9);
break;
case 9:
fill_9.transform.colorTransform = myColorTransform;
gotoAndStop(10);
break;
case 10:
fill_10.transform.colorTransform = myColorTransform;
gotoAndStop(11);
break;
case 11:
fill_11.transform.colorTransform = myColorTransform;
gotoAndStop(12);
break;
case 12:
fill_12.transform.colorTransform = myColorTransform;
gotoAndStop(13);
break;
case 13:
fill_13.transform.colorTransform = myColorTransform;
gotoAndStop(14);
break;
case 14:
fill_14.transform.colorTransform = myColorTransform;
gotoAndStop(15);
break;
case 15:
fill_151.transform.colorTransform = myColorTransform;
btn_next_arrow.removeEventListener(MouseEvent.MOUSE_OVER, hovering);
btn_next_arrow.removeEventListener(MouseEvent.MOUSE_OUT, hideShadow);
btn_back_arrow.removeEventListener(MouseEvent.MOUSE_OVER, hovering1);
btn_back_arrow.removeEventListener(MouseEvent.MOUSE_OUT, hideShadow1);
gotoAndStop(16);
break;
case 16:
gotoAndStop(17);
break;
}
}
btn_next_arrow.addEventListener(MouseEvent.MOUSE_OVER, hovering);
function hovering(e:MouseEvent):void {
trans.color = uint(0x606266);
next_arrow.transform.colorTransform = trans;
}
btn_back_arrow.addEventListener(MouseEvent.MOUSE_OVER, hovering1);
function hovering1(e:MouseEvent):void {
trans1.color = uint(0x606266);
back_arrow.transform.colorTransform = trans1;
}
btn_next_arrow.addEventListener (MouseEvent.MOUSE_OUT, hideShadow);
function hideShadow(event:MouseEvent):void {
trans.color = uint(0x999999);
next_arrow.transform.colorTransform = trans;
}
btn_back_arrow.addEventListener (MouseEvent.MOUSE_OUT, hideShadow1);
function hideShadow1(event:MouseEvent):void {
trans1.color = uint(0x999999);
back_arrow.transform.colorTransform = trans1;
}
btn_back_arrow.addEventListener(MouseEvent.CLICK, goPrevLectFrame);
function goPrevLectFrame(e:MouseEvent):void {
switch(currentFrame){
case 2:
gotoAndStop(1);
break;
case 3:
gotoAndStop(2);
break;
case 4:
gotoAndStop(3);
break;
case 5:
gotoAndStop(4);
break;
case 6:
gotoAndStop(5);
break;
case 7:
gotoAndStop(6);
break;
case 8:
gotoAndStop(7);
break;
case 9:
gotoAndStop(8);
break;
case 10:
gotoAndStop(9);
break;
case 11:
gotoAndStop(10);
break;
case 12:
gotoAndStop(11);
break;
case 13:
gotoAndStop(12);
break;
case 14:
gotoAndStop(13);
break;
case 15:
gotoAndStop(14);
break;
case 16:
gotoAndStop(15);
break;
}
}
btn_main_menu.addEventListener(MouseEvent.CLICK, goPrevLectFrame1);
function goPrevLectFrame1(e:MouseEvent):void {
gotoAndStop(17);
}
stop();
import flash.events.MouseEvent;
btn_goto_lect1.alpha = 0.00001;
btn_goto_pract.alpha = 0.00001;
btn_goto_lect1.addEventListener (MouseEvent.MOUSE_OVER, showShadow);
function showShadow(event:MouseEvent):void {
btn_goto_lect1.alpha = 1;
}
btn_goto_lect1.addEventListener (MouseEvent.MOUSE_OUT, hideShadow_);
function hideShadow_(event:MouseEvent):void {
btn_goto_lect1.alpha = 0.00001;
}
btn_goto_pract.addEventListener (MouseEvent.MOUSE_OVER, showShadow1);
function showShadow1(event:MouseEvent):void {
btn_goto_pract.alpha = 1;
}
btn_goto_pract.addEventListener (MouseEvent.MOUSE_OUT, hideShadow2);
function hideShadow2(event:MouseEvent):void {
btn_goto_pract.alpha = 0.00001;
}
btn_goto_lect1.addEventListener (MouseEvent.CLICK, showShadow3);
function showShadow3(event:MouseEvent):void {
btn_goto_lect1.removeEventListener (MouseEvent.MOUSE_OVER, showShadow);
btn_goto_lect1.removeEventListener (MouseEvent.MOUSE_OUT, hideShadow_);
btn_goto_pract.removeEventListener (MouseEvent.MOUSE_OVER, showShadow1);
btn_goto_pract.removeEventListener (MouseEvent.MOUSE_OUT, hideShadow2);
gotoAndStop(1);
}