PDA

View Full Version : Trouble using "delete" for onEnterFrame method


winfreebot
01-24-2006, 08:05 PM
Hey guys,

I'm having a hard time stopping some objects from calling a method that's running onEnterFrame. I'm trying to delete it, but am having some difficulty. I guess I'm not really sure how delete works. The method is called "mover"and is called here:

for (i=0; i<headlights; i++)
{
t = attachMovie("HeadLight", "headlight"+i, i);
r = (Math.random()*hl_range_x);

t._alpha = 0;
t._x = r + hl_start_x;
t._y = ((0.23 * r) + ((Math.random()* (0.04 * r))-(0.1 * r))) + hl_start_y;

t.onEnterFrame = mover;
}

I think I could delete them one by one using "delete headlight1.onEnterFrame; delete headlight2.onEnterFrame; delete headlight3.onEnterFrame..." all the way up to 100, but I figure there's a better way. Any ideas?

Thanks guys.

sophistikat
01-24-2006, 08:15 PM
does this work?
for (i = 0; i < headlights; i++) {
t = this["headlight" + i];
delete t.onEnterFrame;
}

sophistikat
01-24-2006, 08:21 PM
i ran this test and it does work
function mover () {
trace("hi");
}

var headlights = 50;
for (i = 0; i < headlights; i++) {
t = this.createEmptyMovieClip("headlight" + i, this.getNextHighestDepth());
t.onEnterFrame = mover;
}


for (i = 0; i < headlights; i++) {
t = this["headlight" + i];
delete t.onEnterFrame;
}
if you cut the second for loop, your output window will display keep displaying "hi", paste it back in and nothing pops up because each EnterFrame was deleted

winfreebot
01-24-2006, 08:21 PM
Yes, it works like a charm.

I kept trying t = this("headlight" + i); and was beginning to think you couldn't concatenate variable names or something. Thank you very much Sophistikat.

winfreebot
01-24-2006, 08:22 PM
Thank you for testing it yourself. You're a gentleman and a scholar.

sophistikat
01-24-2006, 08:25 PM
you could use t = eval("headlight" + i); but eval is deprecated so stick with this["headlight" + i];

goliatone
01-24-2006, 08:35 PM
you could use t = eval("headlight" + i); but eval is deprecated so...[/color]
hehehe, its like you (sophistikat) and FG are the only ones i see 'round still using eval...flash 4 reminiscences? ;)

sophistikat
01-25-2006, 12:51 PM
i mentioned eval 'cuz I kept trying t = this("headlight" + i); and i did tell him to stick with this["headlight" + i];... actually i haven't had the time to post this question but in a recent project this, _parent nor _root worked, just eval?? maybe its time to ask why.

goliatone
01-25-2006, 01:03 PM
dont get mad sophistikat, didnt say it in a mean way...is just that eval has been givin me some trouble lately (migration of some flas from f4 to AS.2).

and 'bout your Q, well, i think it would be one for some genious like Senocular or similar, can't help ya. but i would like to know the answer if you get one

sophistikat
01-25-2006, 01:07 PM
not mad :)
i will post my question soon because there have been situation where nothing works but eval()

goliatone
02-04-2006, 01:36 PM
ok, sophistikat...uh, now, Im running into that problem!! well, i dont know if it is the same thing you were talking 'bout, but basically i had some code that isolated worked great, but when integrated in the whole picture, much more complicated, it didnt. went nuts traying to figure it out.

one trouble i had was that an interval that i had set up, didnt execute. Other prob was that some vars were undefined when they shouldnt be.

first, i messed 'round with the vars and in the isolated script worked fine as this.myVar...when in the integrated script didnt work, nor with the full path or anything, only with eval(myVar)...:D (flash 4 reminiscences)

the setInterval was inside a function, if i used it outside that function it would work. but not inside.
my call for the interval was
sliderInterval= setInterval(this, "executeCallback", duration)

i think it fails 'cose this is undefined...i mean, it looks like its just that i made a mess with the scope...

so, what do you think?!

CyanBlue
02-04-2006, 01:53 PM
i think it fails 'cose this is undefined...i mean, it looks like its just that i made a mess with the scope...
I think that'll be the only logical explanation that I can think of... If there is any other reason why it is not working, I think some portion of that belongs to the fault of Macromedia... :D

What I normally do is to pass in the location as a paramter and utilize it... That normally works for me...
some_iv = setInterval("someFunc", 1000, this)
function someFunc(loc)
{
this = loc;
trace("Function someFunc : this = " + this);
}
On the side note...
I was busy at work for the past few months so I was not much active, but I've been keeping my eyes at the forum, and I just want to thank you guys for helping other people at the forum... Your help is much appreciated... Thanks... ;)

goliatone
02-04-2006, 02:23 PM
ok, tnx for the reply CyanBlue...let me get go through it a bit, and think what are you telling me there...:rolleyes: im not so fast.

'bout the side note, i did realize you werent out here as much as you usually are, we definitely missed you and your two cents! :D
I guess its all 'bout learning, giving back, and learn from other peoples issues.

now, ill need to go through that tip you gave here.
;)

CyanBlue
02-06-2006, 02:25 AM
I guess its all 'bout learning, giving back, and learn from other peoples issues.
Very true... :)
now, ill need to go through that tip you gave here.
;)
Yup... Let me know... :)

goliatone
02-06-2006, 10:02 AM
ok, its fixed now...i just made a global object to hold the data of the setInterval and the parameters of the function that was triggered by the setInterval.

Avoid scope issues this way, and at the same time, since all together is a function that powers a slider engine that i have to control from other timelines of the movie is much easyer with the global object...

CyanBlue, 1000tnx for showing me the right track

:)

CyanBlue
02-06-2006, 12:26 PM
Yeah... That method works as well... :)