Delete This.OnEnterFrame ...where?
I'm having troubles killing an onEnterFrame function to keep it from running continuesly (sp?) This is my code:
Code: function fademenu(exceptmenu) { this.onEnterFrame = function() { for (i=1; i<=6; i++) { themenu = _root["menu_"+i+"_mc"]; if (themenu != _root["menu_"+exceptmenu+"_mc"]) { if (themenu._alpha > 0) { themenu._alpha -=70; } else { themenu.gotoAndStop(1); } } } trace ("still running"); } }
...works fine, but keeps running.
I thought i could just do this:
Code: function fademenu(exceptmenu) { this.onEnterFrame = function() { for (i=1; i<=6; i++) { themenu = _root["menu_"+i+"_mc"]; if (themenu != _root["menu_"+exceptmenu+"_mc"]) { if (themenu._alpha > 0) { themenu._alpha -=70; } else { themenu.gotoAndStop(1); delete this.onEnterFrame; } } } trace ("still running"); } }
...but that stops it before the _alpha reaches 0
FlashKit > Flash Help > Flash ActionScript
Posted on: 06-13-2005, 06:10 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
OnEnterFrame=null, OnEnterFrame=undefined & Delete OnEnterFrame....
onEnterFrame=null, onEnterFrame=undefined & delete onEnterFrame....
Which one to use??? What are the performance considerations. If all my movieclips on-stage are running a MovieClip.prototype.onEnterFrame = function() {run initial stuff before setting onEnterFrame=null/undefined... }, will there be performance hits? It's sad that delete onEnterFrame doesn't work unless I delete the prototype enterFrame as well, which would make the clips reinitailise itself again once you declare the enterFrame prototype again (i need to do this since there's more movieclips that end up appearing on-stage, and they need to automatically initialises themselves the moment they appear).
It seems that setting enterFrame to null or undefined is the safest way to go about it, since dealing with multiple .swfs would mean using the same MovieClip.prototype, which means I can't afford to flush out one zone of enterFrames (by deleting both null enterframes and MovieClip.prototype.onEnterFrame) if it means the other zones still needs to initialise their clips first...it's just too troublesome and buggy a mechanism to implement! Once MovieClip.prototype.onEnterframe is declared, it should stay. Will there be performance hits as a result of this?
Is there anyway to do this without tricking the engine to call the onLoad function for MCs by typing "//" into each movieclip actionscript box --- or by troublesomingly creating linkage-ids for every movieclip library item!? NO! That's not what i want...they'll only add to the fiile size! How do i execute a certain "constructor/initilisation" function to all Movieclips without linking them to a class in a library? Something to think about.....
Problem With OnEnterFrame And Delete OnEnterFrame
Ok here is the nuts of the problem,
When I delete the onEnterFrame function programatically I can't reassign it later.
Here is what is happening:
I have a method that I call to build a box on the screen over time. I build it overtime using the onEnterFrame function.
When the application is done it delete the onEnterFrame just fine.
Everything works as expected until you try to assign the same method over again to say for instance make the box smaller. Once I try to call it again I can't assign the onEnterFrame again... I have no idea why it is totally strange.
Code:
//Create an interface
//mc:MovieClip, x:Number, y:Number, w:Number, h:Number
InterfaceBuilderClass.prototype.createInterface = function(mc,x,y,w,h)
{
mc.dy = (h/2)*-1
mc.dx = (w/2)*-1
mc.dy1 = h/2
mc.dx1 = w/2
mc.NFRAMES = 40;
mc.controller = this;
mc.t = 0;
mc.onEnterFrame = function()
{
if (this.t++ < this.NFRAMES) {
trace(this.t);
//DELETED DRAWING STUFF THAT IS NOT AFFECTING THE PROBLEM
}else
{
//redraw with rounded corner
//DELETED DRAWING STUFF THAT IS NOT AFFECTING THE PROBLEM
this.controller.executeCallBack()
delete this.onEnterFrame;
}
}
}
Try it for yourself and see if you can make it work.
If anyone else has run into this problem I'd love to know how you resolved it.
Thanks,
Mark
Delete OnEnterFrame
I have a function with an onEnterframe in a seperate swf which loads into a mc called "video"in my main swf.
when it loads I wanted to delete the onEnterFrame so I have said
Code:
//ball = attachMovie("ball", "b"+i, i);
ball.onEnterFrame = spring;
function spring() {
//spring code here
if (_root._currentframe>1) {
this.myText.text = "";
delete this.onEnterFrame;
}
}
Now this works when the swf is played without been loaded into the video mc but if I loaded it into the "video" mc in the main swf it won't delete ball.onEnterFrame and it won't set the myText.text to blank.
I know this is just a scope problem can some please help.
I Cant Delete OnEnterFrame?
Hi
Trying to do what I think should be simple.
I am loading an image into a mc with 10 frames called holder
the code on the mc is as follows
Code:
onClipEvent (enterFrame) {
//first if to make sure that the image has started to load
if (this._totalframes<2) {
bytesLoad = this.getBytesLoaded()/1000;
bytesTot = this.getBytesTotal()/1000;
if (bytesTot>0) {
percent = int((bytesLoad/bytesTot)*100);
_root.main.load_strip.gotoAndStop(percent);
}
trace("bytesLoad = "+bytesLoad)
trace("bytesTot = "+bytesTot)
if ((bytesLoad>=bytesTot) && (bytesTot>0.01)) {
trace("is here")
_root.main.load_strip.gotoAndPlay("isLoaded");
delete this.onEnterFrame;
}
}
}
It will not delete the onEnterFrame function and keeps going? is there something wrong here?
Delete OnEnterFrame
Hi, It won't delete the onEnterFrame. grrr. It has something to deal will AS2 OOPs right?
code:
MovieClip.prototype.tween = function(prop, finalValue, tweenSpeed) {
var prop:Array;
var finalVal:Array;
var tweenSpeed:Number;
if (tweenSpeed == undefined) {
tweenSpeed = .09;
}
this.onEnterFrame = function() {
for (var i = 0; i<=(prop.length-1); i++) {
//easeOut
this[prop[i]] += (finalValue[i]-this[prop[i]])*tweenSpeed;
}
if (this[prop[0]] == finalValue[0]) {
delete onEnterFrame;
trace("deleted!!!!");
}
trace(this[prop[0]]+" / "+finalValue[0]);
};
};
//
onMouseDown = function () {
box.tween(["_xscale", "_yscale"], [400, 500], .09);
};
How Do I Delete This OnEnterFrame?
I have objects that randomly get thrown over the stage. I want the onEnterFrame to stop when they reach their random destination. How do I delete it?
onEnterFrame = function () {
this._x += (this.x-this._x)/this.easing;
this._y += (this.y-this._y)/this.easing;
this.easing = Math.ceil(Math.random()*5)+1;
};
//
this.x = Math.abs(Math.random()*1000);
this.y = Math.abs(Math.random()*700);
How Do I Delete This OnEnterFrame?
How do I delete this onEnterFrame?
onEnterFrame = function () {
this._x += (this.x-this._x)/this.easing;
this._y += (this.y-this._y)/this.easing;
this.easing = Math.ceil(Math.random()*5)+1;
};
Can't Delete OnEnterFrame
Here's my .fla along with 2 clips to test it.
using delete onEnterFrame just doesn't work, and after searching on the forums, I can't find an answer! Someone tell me I just made a silly mistake!
Thanks!
The file is here
Delete OnEnterFrame Help
Hey guys,
I am trying to get this to delete the onEnterFrame after it completes the thing its working on once...How come this is not working? Any help would be appreciated. Thanks!
Code:
this.ratio = 100;
_root.volume = this.ratio;
dragger.onPress = function() {
this.startDrag(true, 0, 12, 45, 12);
this.onEnterFrame = function() {
ratio = Math.round(this._x*100/45);
_root.volume = ratio;
// RIGHT HERE
this.callback = function () {
delete this.onEnterFrame;
}
var intervalXX;
this.intervalXX = setTimeout( this.callback, 1000 );
};
};
dragger.onRelease = dragger.onreleaseOutside=stopDrag;
Delete This.onEnterFrame
Hi all,
I have a general question about
Delete this.onEnterFrame
as a opposed to
this.onEnterFrame = null
Do these both do the same thing or will there be a difference
The code below, is it best to use
ActionScript Code:
delete this.onEnterFrame
or
ActionScript Code:
this.onEnterFrame = null
ActionScript Code:
logo_mc.onEnterFrame = function() {
this._alpha += 10;
if (this._alpha>=100) {
this._alpha == 100;
delete this.onEnterFrame;
}
};
When To Use 'delete OnEnterFrame'?
Hi I have some code that I'm using to scroll movie clips smoothly using a cosine function. Essentially, I want to use it on three different movie clips, or more. But three for now. When I use the code on one movie clip it works fine, but when i use it on multiple clips it slows down. I think there is a way to speed it up by using 'delete this.onEnterFrame' But I'm not sure how to implement this. Any suggestions?
This is the code that I'm using:
ActionScript Code:
function move_item(mc, x_offset) {
mc.onEnterFrame = function() {
xpos = this._x;
xmouse = _root._xmouse;
direct = xdist;
xdist = int(xpos+xmouse)-x_offset;
if (((xdist<0) && (direct>0)) || ((xdist>0) && (direct<0))) {
i = 0;
}
if (xdist != 0) {
i += 5;
j = i*(Math.PI)/180;
if (i>=180) {
i = 0;
}
} else {
i = 0;
}
honk = int(-xmouse+xdist*Math.cos(j))+x_offset;
this._x = honk;
};
}
move_item(_root.masked_photo.block, 200);
move_item(_root.masked_photo.lines, 200);
move_item(_root.masked_photo.text_window, 265);
/* And here is some sample code I used in another SWF. I got it to work but I still don't understand how to use the 'delete this.onEnterFrame' or 'this.onEnterFrame = null;': */
function move_piece(startboxnr, speed, dir) {
move_piece_start(startboxnr, speed, dir);
}
function move_piece_start(mcnr, speed, dir) {
this.shadow["menu_item_"+mcnr].onEnterFrame = function() {
this.t += speed;
if (this.t>=1) {
this.onEnterFrame = null;
move_piece_finish(this, speed, mcnr, dir);
mcnr += dir;
move_piece(mcnr, speed, dir);
}
};
}
function move_piece_finish(mc, speed, mcnr, dir) {
mc.onEnterFrame = function() {
this.t += speed;
if (dir>0) {
this.gotoAndPlay(1);
} else {
this.gotoAndPlay(12);
}
if (this.t>1) {
t = 0;
delete this.onEnterFrame;
}
};
}
Delete This.onEnterFrame
I am trying to understand using onEnterFrame to position MovieClips:
Here is a simple, example:
1) I have a MC on the stage: "content_mc"
2) I position it on stage sucessfully but uncessfully delete onEnterFrame
Here is the sample code:
if (10 < content_mc._x) {
this.onEnterFrame = function(): Void {
content_mc._x += (10 - content_mc._x)* .15;
trace("positioning ="+content_mc._x)
}; // end onE
} else {
delete this.onEnterFrame;
trace ("deleted onEnterFrame")
};
Where To Delete T.onEnterFrame
Hi all. I've created a banner that has two frames on the main timeline. On the first frame is some script to create snow. There is an init() function to set some variables and then a call to a mover() function. The init() function sets t.onEnterFrame = mover(); I have a few movie clips on the stage in the first frame of my main timeline. One of them plays, then at the end has some script to start the next movie clip. At the end of my last movie clip, I have script to advance the main timeline to frame two, where I want everything to stop. I'm having trouble removing the t.onEnterFrame to get the snow to stop moving. I tried creating a global variable "finished" to keep track of when the last movie finishes and advance to frame two of the main timeline, and tried putting an "if" statement inside the mover function to check for this and remove the t.onEnterFrame. No luck. Any help is appreciated. Thanks!
Attach Code
initSnow = function () {
width = 300;
// pixels
height = 250;
// pixels
max_snowsize = 3;
// pixels
snowflakes = 50;
// quantity
for (i=0; i<snowflakes; i++) {
t = attachMovie("snow", "snow"+i, i);
t._alpha = 20+Math.random()*60;
t._x = -(width/2)+Math.random()*(1.5*width);
t._y = -(height/2)+Math.random()*(1.5*height);
t._xscale = t._yscale=50+Math.random()*(max_snowsize*10);
t.k = 1+Math.random()*2;
t.wind = -1.5+Math.random()*(1.4*3);
t.onEnterFrame = moverSnow;
}
};
moverSnow = function() {
this._y += this.k;
this._x += this.wind;
if (this._y>height+10) {
this._y = -20;
}
if (this._x>width+20) {
this._x = -(width/2)+Math.random()*(1.5*width);
this._y = -20;
} else if (this._x<-20) {
this._x = -(width/2)+Math.random()*(1.5*width);
this._y = -20;
if (finished == 1){
delete t.onEnterFrame;
trace("finished");
trace(finished);
}
}
}
Delete This.onEnterFrame
i am using the following AS to scale a movieclip with ease
PHP Code:
onClipEvent(load){
targe_width = _width;
}
onClipEvent(enterFrame){
targe_width = 360;
_width = _width += (targe_width - _width)/3.6;
}
should i be using a delete this.OnEnterFrame when the clip reaches the desired width? the problem is that ive noticed a lag in my tweens and i wonder if this is whats causing it.
any ideas?
Delete This.onEnterFrame
hello peeps,
ok, i have a movie clip with an onEnterFrame event that basically just checks a value. if the value is true, i want to clip event to fire a function, then clear itself (i dont want a movieclip endlessly checking the value in the enterFrame because it can slow the main movie down.) i thought i could do this with delete this.onEnterFrame.
heres an example i'm trying it with....
onClipEvent(enterFrame){
i ++
trace(i)
if (i >= 5){
delete this.onEnterFrame
}
}
so when i >= 5, it should stop tracing, and basically end.
- Liz
Delete This.onEnterFrame
Hi all,
I have a general question about
Delete this.onEnterFrame
as a opposed to
this.onEnterFrame = null
Do these both do the same thing or will there be a difference
The code below, is it best to use
ActionScript Code:
delete this.onEnterFrame
or
ActionScript Code:
this.onEnterFrame = null
ActionScript Code:
logo_mc.onEnterFrame = function() { this._alpha += 10; if (this._alpha>=100) { this._alpha == 100; delete this.onEnterFrame; }};
Delete This.onEnterFrame
Hi all,
Having a problem with deleting an on.EnterFrame (code below and trace output). Obviously what is happening is that it stuck in a continual loop and it is not even hitting the 'else if' and continues until user activates 'teal5_mc.onPress'. I am probably doing something very obvious but I have been looking at the code too long....
Also, if anyone knows of a better way of including a sound to the rollover that would be bonus. Creating a mechanical sliding door sound effect to reveal a link to another site underneath that door.
The whole fla is working currently but obviously the sound loops and is distorted and not good practice to have the continual loop
Cheers,
Dave
//Teal 5 Intertia variables
var teal5up = -450;
var teal5down = 0;
//inertia formula and sound attach
teal5_mc.onRollOver = function() {
if (teal5_mc._y>-445){
this.onEnterFrame = function() {
this._y = this._y+((teal5up-this._y)/16);
sound1.attachSound("Servo01.mp3");
sound1.start(0,1);
trace(teal5_mc._y);
};
}else if (teal5_mc._y>=-445) {
delete this.onEnterFrame;
};
};
teal5_mc.onPress = function() {
if (teal5_mc._y<0){
this.onEnterFrame = function() {
this._y = this._y+((teal5down-this._y)/16);
};
}else if (teal5_mc._y==0) {
delete this.onEnterFrame;
};
};
Output Panel displays from trace
-448.85
-448.9
-448.95
-449
-449.05
-449.1
-449.15
-449.2
-449.25
-449.25
-449.25
-449.25 And continues until user activates 'teal5_mc.onPress'
Delete OnEnterFrame;
i am trying to stop an onEnterframe event and the delete onEnterFrame; doesnt effect it what ever i do.. my code is:
Code:
dragger.onPress = function() {
this.startDrag(true, 18, 133, line._width-40, 133);
this.onEnterFrame = function() {
l = this._x;
trace(l);
};
};
dragger.onRelease = dragger.onReleaseOutside=stopDrag;
where do i put the delete onEnterFrame;?
Delete This.onEnterFrame
i am using the following AS to scale a movieclip with ease
PHP Code:
onClipEvent(load){
targe_width = _width;
}
onClipEvent(enterFrame){
targe_width = 360;
_width = _width += (targe_width - _width)/3.6;
}
should i be using a delete this.OnEnterFrame when the clip reaches the desired width? the problem is that ive noticed a lag in my tweens and i wonder if this is whats causing it.
any ideas?
Re: Delete OnEnterFrame
Hello evey one out there,
I got a nice problem with onEnterFrame, I want to kill this onEnterFrame at the end of the function!!!
But this thing just kept me bugging. Can any one help in killing this onEnterFrame?
Best regards, link: http://www.macrosoftnova.com/venus.html
Cliff.
Where Should I Use Delete Onenterframe?
ActionScript Code:
for (i=0; i<thisArray.length; i++) {
curr_item = curr_menu.attachMovie("menuItem", "item"+i, i);
.....................
curr_item.onEnterFrame = status;
..................
}
function status() {
if (selectedItem != this) {
Tweener.addTween(this.menuItemBG_mc, {_color:0xADA98F, time:0.1, transition:"linear"});
}
if (selectedMenuItem_so.data.menuSelected == this) {
trace("We have a match: "+this);
Tweener.addTween(this.menuItemBG_mc, {_color:0xC55C7B, time:0.1, transition:"linear"});
delete this.onEnterFrame;
}
}
I just want to change the bg of a menuItem by checking if it's equals selectedItem or selectedMenuItem_so.data.menuSelected
Delete OnEnterFrame
Hi, I only want the onEnterFrame checking when needed because I have other onEnterFrame checks going on that need to stay on and I dont want to overload the processor. I tried placing the onEnterFrame function inside an onPress function and then deleting it onRelease but it doesn't wait for the text scrolling easing to finish and it stops short. Any ideas?
ActionScript:
function setDragMask() {
ts.dragger.onPress = function() {
startDrag(this, false, this._x, 0, this._x, ts.theMask._height-this._height);
// The scrolling animation
ts.theText.onEnterFrame = function() {
trace("enterframe");
scrollAmount = (this._height - (ts.theMask._height/1.3))/(ts.theMask._height - ts.dragger._height);
ts.dragger._height = ts.theMask._height/scrollAmount/1/3;
targY = -ts.dragger._y*scrollAmount;
this._y -= Math.round((this._y-targY)/5);
}
}
// Stop the drag
ts.dragger.onRelease = ts.dragger.onReleaseOutside = function () {
stopDrag();
delete ts.theText.onEnterFrame;
trace("");
}
ts.theText.setMask(ts.theMask);
}
Always: Delete This.onEnterFrame;
Is it always necessary when you have an onEnterFrame function to write
D
elete this.onEnterFrame;
once the condition has been met?
thanks.
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;
}
Delete This.onEnterframe Function?
To avoid unneccesary onEnterFrame checks I wonder if i can delete it after '} else {'. I dont want to removeMovieClip.
PHP Code:
onClipEvent(load) {
function expand(endSize) {
this.onEnterFrame = function () {
var myHeight = _height;
if(_height < endSize) {
myHeight = myHeight*1.2 + 1;
if(myHeight > endSize) {
myheight =endSize;
}
} else {
myheight =endSize;
}
_height = _parent.mask._height = myheight;
_parent.videoplayerbg._y = _parent.player._y = myheight + 7;
// delete the onEnterframe function?
}
}
}
Any thougts or cool tricks out there?
//pod
Question: Delete This.onEnterFrame
I don't know why but I can't delete my onEnterFrame. I've done it many times before but I guess I'm doing something wrong right now. I've tried the following code in Flash 5,6,7 and AS 1 and 2:
Code:
onClipEvent(enterFrame){
this._y+=1;
trace(this._y);
if(this._y>=67){
delete this.onEnterFrame;
}
}
That's on a box MC that keeps moving down even after it passes a _y value of 67. Any help would be great, thanks!
Delete OnEnterFrame Problem
Hi everyone,
I want to stop an onEnterFrame event, but "delete onEnterFrame" seems not to work, I don't know why.
The code goes like this:
Code:
onClipEvent (enterFrame) {
//define the bytes to be loaded and loaded ones
var tLoaded, tBytes;
tLoaded = _parent.bandas_imagen.getBytesLoaded();
tBytes = _parent.bandas_imagen.getBytesTotal();
var percentage = int(tLoaded*100/tBytes);
this.bar._xscale = percentage;
//Make sure stream has started
if (isNaN(tBytes) || tBytes<4) {
return;
}
//jump out and play if fully loaded
if (tLoaded/tBytes>=1) {
//now show it
_parent.bandas_imagen._alpha += 10;
//when done -> cut it
if (_parent.bandas_imagen._alpha>=100) {
trace("done!");
// DELETE DOESN'T WORK (??????????????)
delete onEnterFrame;
}
}
}
It traces "done!" infinite times, but it never kills the onEnterFrame event. Please help me, thanks...
[F8] Delete Onenterframe When Finished
I'm working on preloading external jpgs into a container on the main stage. I have that part working. Now I'm trying to fade them in, which works, but i need to delete the onEnterFrame after the image has completely faded in to 100% because it's interfering with other actions that i have, here is what i have so far that pertains to the fading in
Code:
onEnterFrame = function() {
if(_level0.container._alpha<100) {
_level0.container._alpha +=10;
}else{
};
I need to figure out how to delete the onEnterFrame after that particular image has faded in completely. I know it's delete onEnterFrame; normally but if i put that in there too, then the fade in stops too soon. Has to be really simple, but i'm totally not seeing it. Any suggestions would be greatly appreciated. Thanks for you time.
Delete OnEnterFrame In A Class?
i have a class that extends a movieClip...and in it, i defined an onEnterFrame.
Code:
class Me extends MovieClip {
//constructor
//onEnterFrame loop
function onEnterFrame() {
//do stuff
}
function die() {
delete this.onEnterFrame;
//or delete this.onEnterFrame();
}
}
the function die() would get called, but deleting the onEnterFrame doesn't work... obviously this is wrong?
thanks.
Delete OnEnterFrame In Class
Hi,
I am wondering how I can delete the onEnterFrame function in this class:
Code:
class MoveBall extends MovieClip {
private var _nSpeed:Number;
private var tText;
public function set speed (nSpeed) {
_nSpeed = nSpeed;
}
public function move ():Void {
this._x += _nSpeed;
updateAfterEvent ();
if (this._x >= 200) {
this._x = 200;
trace(this._name);
this.tText.text=this._name;
delete onEnterFrame;//not working
}
}
public function onEnterFrame () {
move ();
}
}
thanks,
Jerryj.
Having Trouble With Delete OnEnterFrame...
Hi,
I have a function which starts on one frame, but I'd like it to stop on the following frame - how do I do that??
I've tried doing it by setting a variable and using an 'if' statement to stop it once the variable has changed...but it's not working
I'm not very good with if's and else if's - can anyone help?? I have a bar which remains on stage at all times and pages are loaded into level1. On one of my pages, the bar sticks to _ymouse, but I need it to stop doing that when I exit the page. Can anyone help?? Here's what I've got so far...don't laugh - it kinda works...
_level0.barMC.onEnterFrame = function() {
this.onMouseMove = function () {
var yMouse = _root._ymouse;
if(stick = false){
delete this.onEnterFrame;
}
if(Math.abs(yMouse - this._y) < 1) {
this._y = yMouse;
} else {
this._y -= (this._y-yMouse) / 6;
}
if(_level0.barMC._y<59){
_level0.barMC._y = 59;
}
}
};
Many thanks in advance!!!
Why Is My Delete This.onEnterFrame Not Working?
Even when it traces 50, onEnterFrame is not deleted... what am i doing wrong here?
Code:
MovieClip.prototype.shrink = function(goal, speed) {
this.onEnterFrame = function() {
this._xscale += (goal-this._xscale)/speed;
this._yscale += (goal-this._yscale)/speed;
trace(this._xscale)
};
if (this._xscale <=52) {
trace("done");
delete this.onEnterFrame;
}
};
Stop (but Don't Delete) OnEnterFrame
How do I stop an onEnterFrame loop without deleting it?
Here's the situation: in my underwater scene, there's a starfish sitting there. The starfish movie clip is stopped on its own frame 1. When the shark swims by, if he's within certain coordinates, the starfish goes to the frame marked "react" and plays a sound. Then the starfish goes back to the stop on its timeline frame 1.
ActionScript Code:
starfish_mc.onEnterFrame = function() {
if (shark_mc._x>350 && shark_mc._x<500 && shark_mc._y>200) {
starfish_mc.starfish.gotoAndPlay("react");
}
};
Trouble is, as long as the shark is in the area the onEnterFrame function keeps triggering endlessly. But if I add "delete this.onEnterFrame" inside the "if" statement, then it is disabled for the rest of the time, and the starfish never reacts again.
I know it must be simple, but how do I make the starfish react only once each time the shark passes?
Delete This.onEnterFrame For ._visible
Thanks in advance for any help.
Here's my faulty code:
MOVIE_MC.onRollOver = function() {
this._visible = 0;
if (this._visible>=0) {
this._visible == 0;
delete this.onEnterFrame;
}
};
MOVIE_MC.onRollOut = function() {
this._visible = 0;
if (this._visible>=0) {
this._visible == 0;
delete this.onEnterFrame;
}
};
The blend mode for MOVIE_MC is Alpha; the first part of the code seems to work on it's on (when you rollover MOVIE_MC, the image below becomes completely visible). But with the second part of the code added, when I rollOver the image blinks. WHAT AM I DOING WRONG?!? Please help!
Thx.
I'm Stuck After I Delete OnEnterFrame
I've made a lot of progress on this file thanks to some help from the forum. I've reached a point I can't figure out. In my released() function, I need to call a delete onEnterFrame so that the scripted tweens can run. But how do I "reinstate" the onEnterFrame when the unreleased() function is called so that the original motion can run.
import mx.utils.Delegate
import mx.transitions.Tween;
import mx.transitions.easing.*;
var numClouds:Number = 35;
var fl:Number = 250;
var gravity:Number = .5;
var vx:Number = 0;
var vy:Number = 0;
var vz:Number = 0;
var friction:Number = .97;
var vpX:Number = Stage.width / 2;
var vpY:Number = Stage.height / 2;
var vpY:Number = 400;
var home:MovieClip = this;
var dreamarray:Array = new Array();
dreamarray[0] = "dreamone";
dreamarray[1] = "dreamtwo";
dreamarray[2] = "dreamthree";
dreamarray[3] = "dreamfour";
dreamarray[4] = "dreamfive";
var dreamarrayX:Array = new Array();
dreamarrayX[0] = 0
dreamarrayX[1] = -1800;
dreamarrayX[2] = 2000;
dreamarrayX[3] = 100;
dreamarrayX[4] = -1700;
var dreamarrayZ:Array = new Array();
dreamarrayZ[0] = 0;
dreamarrayZ[1] = 500;
dreamarrayZ[2] = 1000;
dreamarrayZ[3] = 1500;
dreamarrayZ[4] = 2000;
function init() {
for (var i:Number = 0; i<dreamarray.length; i++) {
var dream:MovieClip = home.attachMovie(dreamarray, "dreamarray" + i, i);
dream.x = dreamarrayX;
dream.y = 50;
dream.z = dreamarrayZ;
dream.onRelease = released;
}
}
function inittwo() {
//set Number to more than number of dreams
for (var j:Number = 20; j<numClouds; j++) {
var cloud:MovieClip = attachMovie("cloud", "cloud" + j, j);
cloud.x = Math.random() * 2000 - 800;
cloud.y = 50;
cloud.z = 0 + cloudoffset;
//cloud.onEnterFrame = mover;
cloudoffset += 600;
}
}
function released() {
for (var i=0;i<dreamarray.length;i++){
var t:MovieClip = home["dreamarray"+i];
t.xPos = t._x;
t.yPos = t._y;
t.theScale = t._xscale;
//delete dream.onRelease;
delete onEnterFrame;
if (t != this)
{
//trace(this);
var tw:Tween = new Tween(t,"_xscale",Strong.easeOut,t._xscale,0,1,true);
var tw2:Tween = new Tween(t,"_yscale",Strong.easeOut,t._yscale,0,1,true);
var tw3:Tween = new Tween(t,"_alpha",Strong.easeOut,100,0,1,true);
//trace(t);
//trace(t.xPos);
//trace(t.yPos);
}
else
{
var tw:Tween = new Tween(t,"_xscale",Strong.easeOut,t._xscale,55,1,true);
var tw2:Tween = new Tween(t,"_yscale",Strong.easeOut,t._yscale,55,1,true);
var tw3:Tween = new Tween(t,"_x",Strong.easeOut,t._x,200,1,true);
var tw4:Tween = new Tween(t,"_y",Strong.easeOut,t._y,100,1,true);
var tw5:Tween = new Tween(theText,"_alpha",Strong.easeOut,0,100,1,true);
var s:Object = this;
tw.onMotionStopped = function()
{
s.onRelease = unReleased;
}
}
}
}
function unReleased(){
//delete this.onRelease;
for(var i=0;i<dreamarray.length;i++)
{
var t:MovieClip = home["dreamarray"+i];
if(t != this)
{
var tw:Tween = new Tween(t,"_xscale",Strong.easeOut,0,t.theScale,1,true);
var tw2:Tween = new Tween(t,"_yscale",Strong.easeOut,0,t.theScale,1,true);
var tw3:Tween = new Tween(t,"_alpha",Strong.easeOut,0,100,1,true);
}
else
{
var tw:Tween = new Tween(t,"_xscale",Strong.easeOut,100,t.theScale,1,true);
var tw2:Tween = new Tween(t,"_yscale",Strong.easeOut,100,t.theScale,1,true);
var tw3:Tween = new Tween(t,"_x",Strong.easeOut,t._x,t.xPos,1,true);
var tw4:Tween = new Tween(t,"_y",Strong.easeOut,t._y,t.yPos,1,true);
tw.onMotionStopped = function()
{
for(var i=0;i<dreamarray.length;i++)
{
var t:MovieClip = home["dreamarray"+i];
t.onRelease = Delegate.create(t,released);
//t.onEnterFrame = mover;
}
}
}
}
}
function onEnterFrame():Void {
//if (dreamarray4.z >= 500 && Key.isDown(Key.UP)){
if (zdepth < 55 && Key.isDown(Key.UP)){
vz -= 1;
zdepth += 1;
}
//if(dreamarray4.z >=2000 && Key.isDown(Key.DOWN))
if(zdepth > 0 && Key.isDown(Key.DOWN))
{
vz += 1;
zdepth -= 1;
}
vy -= gravity;
vx *= friction;
vy *= friction;
vz *= friction;
for (var i:Number=0;i<dreamarray.length;i++) {
var dream:MovieClip = home["dreamarray" +i];
dream.x += vx;
dream.y += vy;
dream.z += vz;
if(dream.y < 50)
{
dream.y = 50;
vy = 0;
}
if (dream.z <= -fl) {
//delete dream.z
dream.z._visible = false;
}
else
{
dream.z._visible = true;
var scale:Number = fl / (fl + dream.z);
dream._xscale = dream._yscale = scale*100;
dream._x = vpX + dream.x * scale/2;
dream._y = vpY + dream.y * scale/2;
//dream._x = dream.x * scale/2;
//dream._alpha = scale * 60 + 40;
dream.swapDepths(-dream.z);
}
}
for (var j:Number=0;j<numClouds;j++) {
var cloud:MovieClip = this["cloud" + j];
cloud.x += vx;
cloud.y += vy;
cloud.z += vz;
if(cloud.y < 50)
{
cloud.y = 50;
vy = 0;
}
if (cloud.z <= -fl) {
cloud.z += 5000;
}
else if(cloud.z > 5000 - fl)
{
cloud.z -= 5000;
}
var scale:Number = fl / (fl + cloud.z);
cloud._xscale = cloud._yscale=scale*200;
cloud._x = vpX + cloud.x * scale;
cloud._y = vpY + cloud.y * scale;
cloud._alpha = scale * 60 + 40;
cloud.swapDepths(-cloud.z);
}
}
/*//trying to create the mover function
function mover():Void {
//if (dreamarray4.z >= 500 && Key.isDown(Key.UP)){
if (zdepth < 55 && Key.isDown(Key.UP)){
vz -= 1;
zdepth += 1;
}
//if(dreamarray4.z >=2000 && Key.isDown(Key.DOWN))
if(zdepth > 0 && Key.isDown(Key.DOWN))
{
vz += 1;
zdepth -= 1;
}
vy -= gravity;
vx *= friction;
vy *= friction;
vz *= friction;
for (var i:Number=0;i<dreamarray.length;i++) {
var dream:MovieClip = home["dreamarray" +i];
dream.x += vx;
dream.y += vy;
dream.z += vz;
if(dream.y < 50)
{
dream.y = 50;
vy = 0;
}
if (dream.z <= -fl) {
//delete dream.z
dream.z._visible = false;
}
else
{
dream.z._visible = true;
var scale:Number = fl / (fl + dream.z);
dream._xscale = dream._yscale = scale*100;
dream._x = vpX + dream.x * scale/2;
dream._y = vpY + dream.y * scale/2;
//dream._x = dream.x * scale/2;
//dream._alpha = scale * 60 + 40;
dream.swapDepths(-dream.z);
}
}
for (var j:Number=0;j<numClouds;j++) {
var cloud:MovieClip = this["cloud" + j];
cloud.x += vx;
cloud.y += vy;
cloud.z += vz;
if(cloud.y < 50)
{
cloud.y = 50;
vy = 0;
}
if (cloud.z <= -fl) {
cloud.z += 5000;
}
else if(cloud.z > 5000 - fl)
{
cloud.z -= 5000;
}
var scale:Number = fl / (fl + cloud.z);
cloud._xscale = cloud._yscale=scale*200;
cloud._x = vpX + cloud.x * scale;
cloud._y = vpY + cloud.y * scale;
cloud._alpha = scale * 60 + 40;
cloud.swapDepths(-cloud.z);
}
}
*/
init();
inittwo();
stop();
Delete Function OnEnterframe - Help?
Hi,
I have a function which starts on one frame, but I'd like it to stop on the following frame - how do I do that??
I've tried doing it by setting a variable and using an 'if' statement to stop it once the variable has changed...but it's not working
I'm not very good with if's and else if's - can anyone help?? I have a bar which remains on stage at all times and pages are loaded into level1. On one of my pages, the bar sticks to _ymouse, but I need it to stop doing that when I exit the page. Can anyone help?? Here's what I've got so far...don't laugh - it kinda works...
_level0.barMC.onEnterFrame = function() {
this.onMouseMove = function () {
var yMouse = _root._ymouse;
if(stick = false){
delete this.onEnterFrame;
}
if(Math.abs(yMouse - this._y) < 1) {
this._y = yMouse;
} else {
this._y -= (this._y-yMouse) / 6;
}
if(_level0.barMC._y<59){
_level0.barMC._y = 59;
}
}
};
Many thanks in advance!!!
What To Use In Place Of Delete This.onEnterFrame?
I have some code which is set to move an mc after a delay of 3 seconds. Problem I am having is when used like this, it of course keeps going because I am not telling it to stop:
Code:
function move(){
clearInterval(moveInterval);
_root.bottom.onEnterFrame = function() {
_root.bottom._y += 5;
}
}
moveinterval =setInterval(move,3000);
So, I try using delete onEnterFrame once the clip reaches a y position of 636, but rather than having the smooth transition to this point, it simply jumps to it.
Code:
function move(){
clearInterval(moveInterval);
_root.bottom.onEnterFrame = function() {
_root.bottom._y += 5;
if (_root.bottom._y = 636) {
delete this.onEnterFrame;
}
}
}
moveinterval =setInterval(move,3000);
So I see that this is obviously killing the movement of the mc
Code:
(_root.bottom._y += 5;)
But I am not sure how else to approach keeping the movement going but stopping it once _y = 636;
I tried this to, with the same result:
Code:
function move(){
clearInterval(moveInterval);
_root.bottom.onEnterFrame = function() {
_root.bottom._y += 5;
if (_root.bottom._y = 636) {
_root.bottom.stop();
}
}
}
moveinterval =setInterval(move,3000);
I have looked through forums, have not found any answers or even a hint as to how I would handle this.
Delete OnEnterFrame Causes Later Code To Not Run
i have this code:
ActionScript Code:
gallery_mc.thumbs_mc.onEnterFrame = function() { if (this._currentframe == 95) { loadThumbs(0); delete this.onEnterFrame; } else if (this._currentframe == 105) {for (var i:Number = 0; i < 10; i++) { var target:String = "gallery_mc.thumbs_mc.thumb" + i + "_mc.container_mc"; thumbs_mcl.unloadClip(target); } }};
problem is when i get to 95, everything works well, but when i get to 105, the onEnterFrame had already been deleted so that code doesnt run anymore. how can i accomplish this so that the code on 105 runs?
thanks in advance.
'delete This.onEnterFrame' Troubles
I'm using a number of onEnterFrame functions in my project and to slow down the CPU consumption I want to delete them when they've done their job. I've got this code to work with things like alpha fades, but the delete this.onEnterFrame doesn't work with the easeing code. I think it's the division part of the code that's affecting it. Can someone lend me a hand?
Thanks,
GD
ActionScript Code:
var targetY = 220;this.onEnterFrame = function() { if (blank_mc._y<targetY) { blank_mc._y += (targetY-blank_mc._y)/10; trace("ease"); if (blank_mc._y>targetY) { delete this.onEnterFrame; } }};
Why Delete This.OnEnterFrame Is Not Working?
Can someone see in this code why the delete is not working? (I commented out the y movement to test to see if it was stopping when x = 10, but it's not. What am I doing wrong?
Code:
function moveCBS() {
clearInterval(moveCBSInterval);
_root.container2.onEnterFrame = function() {
this._x -=5;
//this._y -=5;
if (this._x>10) {
this._x = 10;
delete this.onEnterFrame;
}
}
}
moveCBSinterval = setInterval(moveCBS, 1000);
Help With SetInterval / Delete OnEnterFrame
Hi,
Having some difficulty removing an onEnterFrame function for a scaling effect on a map. If I don't remove it, the function seems to loop, causing massive resource usage and slowing down the HTML page its on.
What I want to do is let the function happen when a button is clicked, then for it to stop once its scaled once. The function has to be called from a zoom in, zoom out and a reset button.
I have the basic code below, but this isn't working. Any help would be greatly appreciated.
Code:
//the zoom in button actions
zoomIn_btn.onPress = function() {
clearInterval(zoomInterval);
zoomInterval = setInterval(_root, "zoomIn", 100);
zoomIn();
nicescale();
};
//the scaling effect
function nicescale() {
map_mc.onEnterFrame = function() {
this._xscale = this._yscale += (this.scale-this._xscale)/2;
if (this.activeMovement) {
this._x += (this.x-this._x)/2;
this._y += (this.y-this._y)/2;
}
};
};
//remove the scaling effect
function removescale() {
delete map_mc.onEnterFrame;
scaleInterval = setInterval(_root, "scaleInterval", 100);
}
I know I need to call the 'removescale' function, but at the moment it's not working so I've removed it from the zoomIn_btn.onPress function.
cheers,
iain
Oppisite Of Delete OnEnterFrame?
onEnterFrame = function(){
if(such and such){
delete this.onEnterFrame;
}else if(such and such){
start this.onEnterFrame;
}
}
whats the proper syntax for this one? thanks so much!
Delete Function OnEnterframe - Help?
Hi,
I have a function which starts on one frame, but I'd like it to stop on the following frame - how do I do that??
I've tried doing it by setting a variable and using an 'if' statement to stop it once the variable has changed...but it's not working
I'm not very good with if's and else if's - can anyone help?? I have a bar which remains on stage at all times and pages are loaded into level1. On one of my pages, the bar sticks to _ymouse, but I need it to stop doing that when I exit the page. Can anyone help?? Here's what I've got so far...don't laugh - it kinda works...
_level0.barMC.onEnterFrame = function() {
this.onMouseMove = function () {
var yMouse = _root._ymouse;
if(stick = false){
delete this.onEnterFrame;
}
if(Math.abs(yMouse - this._y) < 1) {
this._y = yMouse;
} else {
this._y -= (this._y-yMouse) / 6;
}
if(_level0.barMC._y<59){
_level0.barMC._y = 59;
}
}
};
Many thanks in advance!!!
What To Use In Place Of Delete This.onEnterFrame?
I have some code which is set to move an mc after a delay of 3 seconds. Problem I am having is when used like this, it of course keeps going because I am not telling it to stop:
Code:
function move(){
clearInterval(moveInterval);
_root.bottom.onEnterFrame = function() {
_root.bottom._y += 5;
}
}
moveinterval =setInterval(move,3000);
So, I try using delete onEnterFrame once the clip reaches a y position of 636, but rather than having the smooth transition to this point, it simply jumps to it.
Code:
function move(){
clearInterval(moveInterval);
_root.bottom.onEnterFrame = function() {
_root.bottom._y += 5;
if (_root.bottom._y = 636) {
delete this.onEnterFrame;
}
}
}
moveinterval =setInterval(move,3000);
So I see that this is obviously killing the movement of the mc
Code:
(_root.bottom._y += 5;)
But I am not sure how else to approach keeping the movement going but stopping it once _y = 636;
I tried this to, with the same result:
Code:
function move(){
clearInterval(moveInterval);
_root.bottom.onEnterFrame = function() {
_root.bottom._y += 5;
if (_root.bottom._y = 636) {
_root.bottom.stop();
}
}
}
moveinterval =setInterval(move,3000);
I have looked through forums, have not found any answers or even a hint as to how I would handle this.
Visiblity, Delete OnEnterFrame
Last edited by wyclef : 2003-06-24 at 12:41.
Ah yes, notorious delete onEnterFrame has gotten the best of me yet again.
I'm running an onEnterFrame script INSIDE an MC named "reflect" which is inside the MC named "sectionMC_07", which resides on the root level. What i'm doing is setting visibility to true if certain conditions are met, and then when those conditions are met I don't want that onEnterFrame check to be running. What seems to be happening is i'm deleting the onEnterFrame and then when I try to set visibility to true again it doesnt work.
ActionScript Code:
MovieClip.prototype.setContent = function(moreThan, lessThan, objectViz) {
this.onEnterFrame = function() {
if (mc1._x>moreThan && mc1._x<lessThan) {
trace(mc1._x);
objectViz._visible=1;
objectViz.gotoAndPlay("start");
sectionMC_07._visible=1;
sectionMC_07.gotoAndPlay("start");
delete (this.onEnterFrame);
} else {
delete (this.sectionMC_07.reflect.onEnterFrame);
trace("false");
}
};
};
// --------------------------------------------------------------------------------------
setVisibility = function () {
for(i=0;i<8;i++){
this["sectionMC_0"+i]._visible=0;
}
};
setVisibility();
sectionMC_00._visible=1;
sectionMC_00.gotoAndPlay("start");
sectionMC_06._visible=1;
sectionMC_06.gotoAndPlay("start");
sectionMC_07._visible=1;
sectionMC_07.gotoAndPlay("start");
// --------------------------------------------------------------------------------------
Here is the onEnterFrame code...
ActionScript Code:
onEnterFrame = function() {
amount = 1;
while (amount>0) {
duplicateMovieClip (flower, "mc"+i, i);
setProperty ("mc"+i, _x, random(710));
setProperty ("mc"+i, _y, random(143));
setProperty ("mc"+i, _alpha, random(275));
setProperty ("mc"+i, _xscale, random(100));
setProperty ("mc"+i, _yscale, random(100));
i++;
amount--;
trace("reflectEnter");
}
}
|