|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
delete onEnterFrame
is this the correct use of delete onenterFrame?
a_mc.onEnterFrame = function(){ moveEm(a_mc, 55); if(moveEm(a_mc, 55);{ delete (this.onEnterFrame); }; b_mc.onEnterFrame = function() { moveEm(b_mc, 60); if(moveEm(a_mc, 55);{ delete (this.onEnterFrame); }; c_mc.onEnterFrame = function() { moveEm(c_mc, 70); if(moveEm(a_mc, 55);{ delete (this.onEnterFrame); }; d_mc.onEnterFrame = function() { moveEm(d_mc, 75); if(moveEm(a_mc, 55);{ delete (this.onEnterFrame); }; function moveEm(who, howMuch) { Xsquare = who._x; Xdiff = who.Xpos-Xsquare; Xmove = Xdiff/howMuch; who._x = Xsquare+Xmove; } |
|
#2
|
|||
|
|||
|
Well I think you should omit the () are you getting some kind of error or somethin, or just asking?
PHP Code:
|
|
#3
|
|||
|
|||
|
well, i've actually updated the code since then, maybe you could take a look at the updated script and see if you think it can be made more efficient.
function moveEm(who, howMuch) { Xsquare = who._x; Xdiff = who.Xpos-Xsquare; Xmove = Xdiff/howMuch; who._x = Xsquare+Xmove; if (Math.ceil(Xmove) == 0) return 1; } a_mc.val = 9; b_mc.val = 12; c_mc.val = 15; nav.btn_00.onRelease = function() { _root.a_mc.Xpos = 0; _root.b_mc.Xpos = 0; _root.c_mc.Xpos = 0; _root.a_mc.onEnterFrame = moveA; _root.b_mc.onEnterFrame = moveB; _root.c_mc.onEnterFrame = moveC; loadMovie("xx.swf", "_root.movieclip"); }; nav.btn_01.onRelease = function() { _root.a_mc.Xpos = -764; _root.b_mc.Xpos = -484; _root.c_mc.Xpos = -240; _root.a_mc.onEnterFrame = moveA; _root.b_mc.onEnterFrame = moveB; _root.c_mc.onEnterFrame = moveC; loadMovie("xx.swf", "_root.movieclip"); }; nav.btn_02.onRelease = function() { _root.a_mc.Xpos = -1527; _root.b_mc.Xpos = -968; _root.c_mc.Xpos = -480; _root.a_mc.onEnterFrame = moveA; _root.b_mc.onEnterFrame = moveB; _root.c_mc.onEnterFrame = moveC; loadMovie("xx.swf", "_root.movieclip"); }; nav.btn_03.onRelease = function() { _root.a_mc.Xpos = -2290; _root.b_mc.Xpos = -1452; _root.c_mc.Xpos = -720; _root.a_mc.onEnterFrame = moveA; _root.b_mc.onEnterFrame = moveB; _root.c_mc.onEnterFrame = moveC; loadMovie("xx.swf", "_root.movieclip"); }; nav.btn_04.onRelease = function() { _root.a_mc.Xpos = -3053; _root.b_mc.Xpos = -1936; _root.c_mc.Xpos = -960; _root.a_mc.onEnterFrame = moveA; _root.b_mc.onEnterFrame = moveB; _root.c_mc.onEnterFrame = moveC; loadMovie("xx", "_root.movieclip"); }; nav.btn_05.onRelease = function() { _root.a_mc.Xpos = -3816; _root.b_mc.Xpos = -2420; _root.c_mc.Xpos = -1200; _root.a_mc.onEnterFrame = moveA; _root.b_mc.onEnterFrame = moveB; _root.c_mc.onEnterFrame = moveC; loadMovie("xx", "_root.movieclip"); }; function moveA() { rtnValue = _root.moveEm(_root.a_mc, _root.a_mc.val); if (rtnValue == 1) { trace("Deleting this.onEnterFrame " + this._name); delete this.onEnterFrame; } } function moveB() { rtnValue = _root.moveEm(_root.b_mc, _root.b_mc.val); if (rtnValue == 1) { trace("Deleting this.onEnterFrame " + this._name); delete this.onEnterFrame; } } function moveC() { rtnValue = _root.moveEm(_root.c_mc, _root.c_mc.val); if (rtnValue == 1) { trace("Deleting this.onEnterFrame " + this._name); delete this.onEnterFrame; } } |
|
#4
|
|||
|
|||
|
Could you give me some background on what the code does? Its hard to tell because there are no comments or sample .fla.
|
|
#5
|
|||
|
|||
|
Basically,
there are 3 super long bitmap files a_mc, b_mc, and c_mc and when you click on btn_00, btn_01, btn_02, btn_03, btn_04, and btn_05 these bitmaps move to a designated _x position at different speeds. On slower computers this kills the processor so i've been trying to figure out how to one. delete onEnterframe in the most efficient manner, and just see if there is a way to help the script work better. |
|
#6
|
|||
|
|||
|
any ideas? i'd really like to make this script as efficient as possible and I suspect this is a very inefficient script.
|
|
#7
|
|||
|
|||
|
Maybe this will help
Based on your code, I created something that should give you a few ideas. It isn't necessarily the ideal scenario, but it will give you ideas for more reusable code.
Also, I recommend Robert Penner's easing equations for actionscript-based movement. hth, Mike Britton On Stage (instance names): mc0, mc1, mc2 btn0, btn1, btn2 Code:
var mcVals = ["9", "12", "15"];
this.moveEm = function(mc, howMuch) {
trace("movEm hit.");
Xsquare = _root[mc]._x;
_root[mc].Xpos = getXpos(mc);
Xdiff = _root[mc].Xpos-Xsquare;
Xmove = Xdiff/howMuch;
_root[mc]._x = Xsquare+Xmove;
if (Math.ceil(Xmove) == 0)
return 1;
};
this.buttonCommands = function(mc, btn, pos) {
_root[btn].onRelease = function() {
var pos = getXPos(pos);
_root[mc].onEnterFrame = function() {
var rtnValue = moveEm(mc, pos);
if (rtnValue == 1) {
delete _root[mc].onEnterFrame;
}
}
};
};
this.getXPos = function(p) {
if (p == 0) {
Xpos = 20;
} else if (p == 1) {
Xpos = 10*p;
} else if (p == 2) {
Xpos = 5*p;
} else {
Xpos = 0;
}
return Xpos;
};
// Usage:
for (i=0; i<mcVals.length; i++) {
var mc = "mc"+i;
var btn = "btn"+i;
var pos = i;
buttonCommands(mc, btn, pos);
}
__________________
I'm not impatient, I just have a low tolerance for boredom. |
![]() |
| Viewing: Dev Shed Forums > Web Design > Flash Help > delete onEnterFrame |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|