Be a Supporter!

AS3 Function Arguments

  • 349 Views
  • 4 Replies
New Topic Respond to this Topic
IndigenousDigitalist
IndigenousDigitalist
  • Member since: Sep. 24, 2010
  • Offline.
Forum Stats
Member
Level 13
Game Developer
AS3 Function Arguments Jan. 28th, 2013 @ 10:39 PM Reply

So I have a function that looks at a MovieClip called char that has its own class and changes its x and y values based on its proximity to another MovieClip. I had this function so that it always ran with char as the MovieClip and it worked fine, but now I want to be able to have other MovieClips that don't have their own class (I could make one for them if that would make solving the problem easier) able to be used by the function as well. Since the char isn't of the MovieClip class, is there a way that I could declare an argument within the function that could be of either the char or MovieClip class? Would it be something like this?:

function changeXY(item:(char, MovieClip)){
//Do stuff
}

Any help would be greatly appreciated


BBS Signature
IndigenousDigitalist
IndigenousDigitalist
  • Member since: Sep. 24, 2010
  • Offline.
Forum Stats
Member
Level 13
Game Developer
Response to AS3 Function Arguments Jan. 28th, 2013 @ 10:47 PM Reply

Also, don't know if it's important, but the char class extends the MovieClip class, just throwing that out there as well


BBS Signature
MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to AS3 Function Arguments Jan. 28th, 2013 @ 10:59 PM Reply

At 1/28/13 10:47 PM, IndigenousDigitalist wrote: Also, don't know if it's important, but the char class extends the MovieClip class, just throwing that out there as well

If char (capitalize the first letter of class names) extends movieclip, then char IS of the movieclip class. Just use

functionName(item:MovieClip)

as the param. As long as you aren't doing anything char-specific, it'll only focus on the movieclip aspect of whatever you pass in.

IndigenousDigitalist
IndigenousDigitalist
  • Member since: Sep. 24, 2010
  • Offline.
Forum Stats
Member
Level 13
Game Developer
Response to AS3 Function Arguments Jan. 28th, 2013 @ 11:20 PM Reply

At 1/28/13 10:59 PM, MSGhero wrote:
At 1/28/13 10:47 PM, IndigenousDigitalist wrote: Also, don't know if it's important, but the char class extends the MovieClip class, just throwing that out there as well
If char (capitalize the first letter of class names) extends movieclip, then char IS of the movieclip class. Just use

functionName(item:MovieClip)

as the param. As long as you aren't doing anything char-specific, it'll only focus on the movieclip aspect of whatever you pass in.

Ok, thanks, I guess the error doesn't have to do with that then, I was just thinking of possibilities for what was wrong


BBS Signature
milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to AS3 Function Arguments Jan. 29th, 2013 @ 03:10 AM Reply

Use the super class that defines the properties you're using: DisplayObject