Be a Supporter!

Function help (as3)

  • 329 Views
  • 2 Replies
New Topic Respond to this Topic
Gimmick
Gimmick
  • Member since: Aug. 20, 2008
  • Offline.
Forum Stats
Member
Level 27
Game Developer
Function help (as3) May. 21st, 2011 @ 05:11 AM Reply

I have a movieclip with a class of "person". Now, I have a public function called "moveX" in it, which is:

package  {
	
	import flash.display.MovieClip;
	
	
	public class person extends MovieClip {
		
		
		public function person() {
	        public var movespeed:Number = 0
		}
                public function moveX(movespeed:Number){
                this.x += movespeed
                }
	}
	
}

Now, on the stage I have this applied:

var mc:person = new person();
stage.addChild(mc)
mc.moveX(4)

but when I compile it, I get these errors:

TypeError: Error #1006: moveX is not a function.
	at Untitled_fla::MainTimeline/frame1()

What am I doing wrong here?


Slint approves of me! | "This is Newgrounds.com, not Disney.com" - WadeFulp
"Sit look rub panda" - Alan Davies

BBS Signature
Torrunt
Torrunt
  • Member since: May. 3, 2007
  • Offline.
Forum Stats
Member
Level 22
Programmer
Response to Function help (as3) May. 21st, 2011 @ 06:01 AM Reply

You're initializing a variable in the constructor which you shouldn't do unless you just want to use it in there. You also don't even need that variable at all, not sure why you have it there :S Since it has the same name as you're parameter for moveX, maybe you put that there thinking it would make it's default value 0. In that case you just put = 0 where you declared it:

public function moveX(movespeed:Number = 0){

Also you pretty much never need to use 'this' in AS3, you can just say 'x'.


BBS Signature
MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Function help (as3) May. 21st, 2011 @ 06:43 AM Reply

You can't use packages or classes in the flash IDE, use external .as files.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature