00:00
00:00
Newgrounds Background Image Theme

twmimic001 just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

AS3 Function Arguments

603 Views | 4 Replies
New Topic Respond to this Topic

AS3 Function Arguments 2013-01-28 22:39:48


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

Response to AS3 Function Arguments 2013-01-28 22:47:52


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

Response to AS3 Function Arguments 2013-01-28 22:59:45


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.

Response to AS3 Function Arguments 2013-01-28 23:20:19


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

Response to AS3 Function Arguments 2013-01-29 03:10:50


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