Copy link to clipboard
Copied
I'm curious to know if there is any examples you all could give me any examples of copying a function in AS3; then use that copy independent of the original function it copied.
I want to make an animation system that heavily depends on one type of function. Since it depends on one type of function, I cant have every single piece of code calling back to the same function if I want to use it multiple times.
Is there a way of properly doing this? are their performance consequences?
I'd really like to do this instead of writing several different functions out separately that work nearly the same. (plus I need to feed a set of values into those functions that are created, some being called by event listeners of course)
Anybody have any ideas or can point me in the right direction?
Hi,
@MrKnives
I think you could create instance of object that could encapsulate your set of that data and then execute it to process data. It could be as simple as some util class that once created expose method you could call at any later time to process given set of data.
If you want to decouple such implementation from your actual context i think you could apply Action/Command patter, see:
http://en.wikipedia.org/wiki/Command_pattern
...
object is used to represent and encapsulate all the information
Copy link to clipboard
Copied
What makes you conclude that you cannot have the same function called multiple times?
Copy link to clipboard
Copied
correct me if I'm wrong but I think he is trying to pass a Function object to multiple other objects, say .swf files. I just ran into this problem. The thing is, is that if you pass a Function object to one swf file, then you can't pass that same function to another swf. Or atleast that's what seemed to happen to me. I worked my way around it by passing the main .swf to the loaded .swfs and then using that reference to call the function.
Copy link to clipboard
Copied
because the set of data I'd feed into it using data from external variables would be different each time even if I copied the values to the function itself. That's why I "assume" that, if you want to put it that way.
Also, your response doesnt answer my question.
Copy link to clipboard
Copied
My response wasn't intended to answer your question, it was intended to start a discussion to see whether or not you can use the same function for multiple items. It is common to do so -- both discuss things and have the same function called multiple times. You should show what you are trying to accomplish. It could help anyone trying to help you.
PS - why did you quote "assume"? I did not use that word. Chances are you are reading something into my response that isn't there... which might account for what comes across as a - no thanks - response on your part.
Copy link to clipboard
Copied
Hi,
@MrKnives
I think you could create instance of object that could encapsulate your set of that data and then execute it to process data. It could be as simple as some util class that once created expose method you could call at any later time to process given set of data.
If you want to decouple such implementation from your actual context i think you could apply Action/Command patter, see:
http://en.wikipedia.org/wiki/Command_pattern
object is used to represent and encapsulate all the information needed to call a method at a later time. This information includes the method name, the object that owns the method and values for the method parameters.
http://www.google.com/search?btnG=1&pws=0&q=Action+command+pattern+ActionScript
regards,
Peter
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more