Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Copying functions in ActionScript 3 (to duplicate a function then use it)

New Here ,
May 21, 2011 May 21, 2011

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?

TOPICS
ActionScript
899
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , May 22, 2011 May 22, 2011

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

...
Translate
LEGEND ,
May 21, 2011 May 21, 2011

What makes you conclude that you cannot have the same function called multiple times?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 21, 2011 May 21, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 21, 2011 May 21, 2011

@Ned Murphy

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 22, 2011 May 22, 2011
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 22, 2011 May 22, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines