Flash Function ?
- Started
- Last post
- 8 Responses
- thirtytwo
Quick Question: If I delete a function, can I call it again or start it back up?
- tGP0
what do you mean by "delete a function"...
once you set a function, you can call it again and again if the scope is correct...
- thirtytwo0
delete this.onEnterFrame;
or
delete _level1.phmc.rotatemc;
- Seph0
if you deleted it textually and you havent saved the file and its still open - do the following:
navigate in flash to where the actionscript was written, click in the panel as if you were about to write something then:
cntrl z cntrl z cntrl z cntrl z cntrl z cntrl z cntrl zcntrl z cntrl z cntrl z cntrl z cntrl z
- thirtytwo0
I did not delete the file, I have a function that takes up a lot of CPU, so I remove the function by "delete", I was wondering if I could call the function again later.
Like starting it again.
- thirtytwo0
I did not delete the file, I have a function that takes up a lot of CPU, so I remove the function by "delete", I was wondering if I could call the function again later.
Like starting it again.
- Seph0
An elegant way would be to use addlistener and removelistener?
Or do it the ugly way and stick a boolean in a conditional at the start of the function then set the boolean to false when you dont want it to function and true when you do.
- loahn0
the "delete" function in flash is a fine alternative to setInterval/clearInterval.
delete this.onEnterFrame is good and will not pysically/textually delete the prototype, class of function that is running. It'll just stop the script from running temporarily for the instance that addresses it. Its a good idea to use trace() actions to report the surrent status as flash doesn;t always evaluate Maths to an expected value.
e.g. you have am onEnterFrame running and you're checking if _xscale == 100 it should delete the onEnterFrame. However, flash will probably only accurately get to 98.7 c.a. which will cause the script to run forever as it never reaches its target of 100.
In short you'll need to tweak it so it rounds up or down to a whole number.
- propa0
This is very interesting. I like the concept of delete instead of using setInterval. That cleans things up a bit and you don't have to worry about interval ids as much. If you attach setInt to an object all you have to do is find that object and delete the eventhandler.
Nice.