Flash Actionscript 2:功能赢得';跑不动
我定义了一个函数并尝试运行它,但它不会运行,如果我从函数中取出代码,它会正常运行,但我无法找出原因,下面是函数和调用Flash Actionscript 2:功能赢得';跑不动,flash,actionscript,actionscript-2,Flash,Actionscript,Actionscript 2,我定义了一个函数并尝试运行它,但它不会运行,如果我从函数中取出代码,它会正常运行,但我无法找出原因,下面是函数和调用 function Boomclat() { var TweenX:Tween = new Tween(this, "_x", mx.transitions.easing.Strong.easeOut, this._x, 16.9, 1, true); var TweenY:Tween = new Tween(this, "_y", mx.tran
function Boomclat() {
var TweenX:Tween = new Tween(this, "_x", mx.transitions.easing.Strong.easeOut, this._x, 16.9, 1, true);
var TweenY:Tween = new Tween(this, "_y", mx.transitions.easing.Strong.easeOut, this._y, listY, 1, true);
}
Boomclat();
这是我的全部代码(在这个MC上,有更多的外部代码):
onClipEvent(加载){
导入mx.transitions.Tween;
导入mx.transitions.xml;
startX=这个;
startY=这个;
mn=0;
}
onClipEvent(enterFrame){
this.onRollOver=函数(){
这个。停止(“结束”);
};
this.onRollOut=函数(){
这是。停止(“向上”);
};
this.onPress=函数(){
这个。停止(“向下”);
};
this.onReleaseOutside=函数(){
这是。停止(“向上”);
};
this.onRelease=函数(){
这是。停止(“向上”);
this.enabled=false;
此.arrow.gotoAndStop(“已订购”);
如果(_global.hasAnswered!=1){
this.arrow.listNumber=this.\u parent.Order.length+1;
listY=35+(74.9*this.\u parent.Order.length);
这个.\u父.命令.推送(这个);
函数Boomclat(){
var TweenX:Tween=新Tween(this,“x”,mx.transitions.easing.Strong.easeOut,this.x,16.9,1,true);
var TweenY:Tween=新Tween(this,“_y”,mx.transitions.easing.Strong.easeOut,this._y,listY,1,true);
};
Boomclat();
此._parent.buttonHolder.previousOrder.push(此);
}否则{
对于(i=0;iAS2中最常见的错误原因之一是范围问题。可能this
关键字没有引用您在Boomclat函数中想要的对象。您可以在函数中添加一个跟踪调用,trace(this)
,以查看它是否是您想要插入的对象
编辑:我现在看到Boomclat是在另一个函数onRelease处理程序中定义的。我不确定您是否可以使用这种确切的语法来完成。如果您想要嵌套函数,一种方法是这样做,将函数引用存储在局部变量中:
var boomclat:Function = function () {
var TweenX:Tween = new Tween(this, "_x", mx.transitions.easing.Strong.easeOut, this._x, 16.9, 1, true);
var TweenY:Tween = new Tween(this, "_y", mx.transitions.easing.Strong.easeOut, this._y, listY, 1, true);
};
boomclat();
或者您可以在onRelease处理程序之外的其他地方定义函数,而只从onRelease处理程序调用它
但是考虑到您发布的代码,我想说您也可以内联执行代码,我真的不明白您为什么需要该函数。为什么要循环Boomclat()函数?
很明显,在再次触发吐温之前,吐温效应不会结束,甚至可能不会开始。实际上,重新设置吐温
[编辑]
Opps,出于某种原因,我认为函数调用在函数内部。
无论如何,您是否验证了变量在函数内部是可访问的。
function Boomclat() {
trace( this._x )
trace( this._y _ )
trace( listY )
var TweenX:Tween = new Tween(this, "_x", mx.transitions.easing.Strong.easeOut, this._x, 16.9, 1, true);
var TweenY:Tween = new Tween(this, "_y", mx.transitions.easing.Strong.easeOut, this._y, listY, 1, true);
}
Boomclat();
[EDIT2]
//remove the onClipEvent completely and you should be ok
import mx.transitions.Tween;
import mx.transitions.easing.*;
startX = this._x;
startY = this._y;
this.onRollOver = function() {
this.gotoAndStop("over");
};
this.onRollOut = function() {
this.gotoAndStop("up");
};
this.onPress = function() {
this.gotoAndStop("down");
};
this.onReleaseOutside = function() {
this.gotoAndStop("up");
};
// you might have to fix the references to this._parent to get it target what you want.
this.onRelease = function() {
this.gotoAndStop("up");
this.enabled = false;
this.arrow.gotoAndStop("ordered");
if (_global.hasAnswered != 1) {
this.arrow.listNumber = this._parent.Order.length+1;
listY = 35+(74.9*this._parent.Order.length);
this._parent.Order.push(this);
orderTween();
this._parent.buttonHolder.previousOrder.push(this);
} else {
for (i=0; i<this._parent.trueOrder.length; i++) {
if (this == this._parent.trueOrder[i]) {
_global.previousButton.enabled = true;
_global.previousButton.gotoAndStop("up");
myColor = new Color(_global.previousButton);
myColor.setTint(255,255,255,0);
myColor = new Color(this);
myColor.setTint(113,205,0,23);
this.gotoAndStop("down");
var TweenX:Tween = new Tween(_global.lastText, "_x", mx.transitions.easing.Back.easeOut, 276.4, -210, 0.7, true);
_global.whichText = this._parent.textFile[i];
var TweenX:Tween = new Tween(_global.whichText, "_x", mx.transitions.easing.Back.easeOut, 760, 276.4, 0.7, true);
_global.lastText = whichText;
_global.previousButton = this;
}
}
}
};
// as you can see I put it last
function orderTween() {
var TweenX:Tween = new Tween(this, "_x", mx.transitions.easing.Strong.easeOut, this._x, 16.9, 1, true);
var TweenY:Tween = new Tween(this, "_y", mx.transitions.easing.Strong.easeOut, this._y, listY, 1, true);
}
//完全删除onClipEvent,您应该可以
导入mx.transitions.Tween;
导入mx.transitions.xml;
startX=这个;
startY=这个;
this.onRollOver=函数(){
这个。停止(“结束”);
};
this.onRollOut=函数(){
这是。停止(“向上”);
};
this.onPress=函数(){
这个。停止(“向下”);
};
this.onReleaseOutside=函数(){
这是。停止(“向上”);
};
//您可能必须修复对此的引用。\u parent才能使其成为您想要的目标。
this.onRelease=函数(){
这是。停止(“向上”);
this.enabled=false;
此.arrow.gotoAndStop(“已订购”);
如果(_global.hasAnswered!=1){
this.arrow.listNumber=this.\u parent.Order.length+1;
listY=35+(74.9*this.\u parent.Order.length);
这个.\u父.命令.推送(这个);
orderTween();
此._parent.buttonHolder.previousOrder.push(此);
}否则{
对于(i=0;i,奇怪的是,如果我在onRelease之前定义函数,它就可以工作了……下面是最终代码:
onClipEvent (load) {
import mx.transitions.Tween;
import mx.transitions.easing.*;
function orderTween() {
var TweenX:Tween = new Tween(this, "_x", mx.transitions.easing.Strong.easeOut, this._x, 16.9, 1, true);
var TweenY:Tween = new Tween(this, "_y", mx.transitions.easing.Strong.easeOut, this._y, listY, 1, true);
}
startX = this._x;
startY = this._y;
this.onRollOver = function() {
this.gotoAndStop("over");
};
this.onRollOut = function() {
this.gotoAndStop("up");
};
this.onPress = function() {
this.gotoAndStop("down");
};
this.onReleaseOutside = function() {
this.gotoAndStop("up");
};
this.onRelease = function() {
this.gotoAndStop("up");
this.enabled = false;
this.arrow.gotoAndStop("ordered");
if (_global.hasAnswered != 1) {
this.arrow.listNumber = this._parent.Order.length+1;
listY = 35+(74.9*this._parent.Order.length);
this._parent.Order.push(this);
orderTween();
this._parent.buttonHolder.previousOrder.push(this);
} else {
for (i=0; i<this._parent.trueOrder.length; i++) {
if (this == this._parent.trueOrder[i]) {
_global.previousButton.enabled = true;
_global.previousButton.gotoAndStop("up");
myColor = new Color(_global.previousButton);
myColor.setTint(255,255,255,0);
myColor = new Color(this);
myColor.setTint(113,205,0,23);
this.gotoAndStop("down");
var TweenX:Tween = new Tween(_global.lastText, "_x", mx.transitions.easing.Back.easeOut, 276.4, -210, 0.7, true);
_global.whichText = this._parent.textFile[i];
var TweenX:Tween = new Tween(_global.whichText, "_x", mx.transitions.easing.Back.easeOut, 760, 276.4, 0.7, true);
_global.lastText = whichText;
_global.previousButton = this;
}
}
}
};
}
onClipEvent(加载){
导入mx.transitions.Tween;
导入mx.transitions.xml;
函数orderTween(){
var TweenX:Tween=新Tween(this,“x”,mx.transitions.easing.Strong.easeOut,this.x,16.9,1,true);
var TweenY:Tween=新Tween(this,“_y”,mx.transitions.easing.Strong.easeOut,this._y,listY,1,true);
}
startX=这个;
startY=这个;
this.onRollOver=函数(){
这个。停止(“结束”);
};
this.onRollOut=函数(){
这是。停止(“向上”);
};
this.onPress=函数(){
这个。停止(“向下”);
};
this.onReleaseOutside=函数(){
这是。停止(“向上”);
};
this.onRelease=函数(){
这是。停止(“向上”);
this.enabled=false;
此.arrow.gotoAndStop(“已订购”);
如果(_global.hasAnswered!=1){
this.arrow.listNumber=this.\u parent.Order.length+1;
listY=35+(74.9*this.\u parent.Order.length);
这个.\u父.命令.推送(这个);
orderTween();
此._parent.buttonHolder.previousOrder.push(此);
}否则{
对于(i=0;这不是答案,但我认为您不应该在enterFrame事件中有onRelease等的定义。您只需要运行这些代码,enterFrame将重复执行很多次(例如每秒24次,每秒24帧)是的,我认为他们需要连续运行来识别滚动等,显然不是欢呼。如果没有函数外部的tweens,它工作得很好,而且函数根本没有运行,我可以将跟踪(“hello”)
进入函数,它不会输出,因此函数永远不会运行。正如Lars在下文中所述,您有一个范围问题,加上您正在onClipEvent内部定义鼠标事件以及导入语句。您需要将这些函数从onClipEvent函数中拉出。您发布的代码不是质量代码(很抱歉直言不讳)。ActionScript2对于scop来说可能非常棘手
onClipEvent (load) {
import mx.transitions.Tween;
import mx.transitions.easing.*;
function orderTween() {
var TweenX:Tween = new Tween(this, "_x", mx.transitions.easing.Strong.easeOut, this._x, 16.9, 1, true);
var TweenY:Tween = new Tween(this, "_y", mx.transitions.easing.Strong.easeOut, this._y, listY, 1, true);
}
startX = this._x;
startY = this._y;
this.onRollOver = function() {
this.gotoAndStop("over");
};
this.onRollOut = function() {
this.gotoAndStop("up");
};
this.onPress = function() {
this.gotoAndStop("down");
};
this.onReleaseOutside = function() {
this.gotoAndStop("up");
};
this.onRelease = function() {
this.gotoAndStop("up");
this.enabled = false;
this.arrow.gotoAndStop("ordered");
if (_global.hasAnswered != 1) {
this.arrow.listNumber = this._parent.Order.length+1;
listY = 35+(74.9*this._parent.Order.length);
this._parent.Order.push(this);
orderTween();
this._parent.buttonHolder.previousOrder.push(this);
} else {
for (i=0; i<this._parent.trueOrder.length; i++) {
if (this == this._parent.trueOrder[i]) {
_global.previousButton.enabled = true;
_global.previousButton.gotoAndStop("up");
myColor = new Color(_global.previousButton);
myColor.setTint(255,255,255,0);
myColor = new Color(this);
myColor.setTint(113,205,0,23);
this.gotoAndStop("down");
var TweenX:Tween = new Tween(_global.lastText, "_x", mx.transitions.easing.Back.easeOut, 276.4, -210, 0.7, true);
_global.whichText = this._parent.textFile[i];
var TweenX:Tween = new Tween(_global.whichText, "_x", mx.transitions.easing.Back.easeOut, 760, 276.4, 0.7, true);
_global.lastText = whichText;
_global.previousButton = this;
}
}
}
};
}