2 Replies - 623 Views - Last Post: 20 June 2009 - 09:32 AM

#1 Ryan1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 29-September 07

How would this be done in AS3?

Post icon  Posted 14 June 2009 - 09:35 AM

How would you use a MovieClip that's in the library in a document class?

Thanks
Is This A Good Question/Topic? 0
  • +

Replies To: How would this be done in AS3?

#2 UnknownFury  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 17
  • Joined: 09-March 09

Re: How would this be done in AS3?

Posted 14 June 2009 - 10:02 AM

View PostRyan1, on 14 Jun, 2009 - 08:35 AM, said:

How would you use a MovieClip that's in the library in a document class?

Thanks


Right click the MC in the library and click linkage. You can then give it a class name. If that class exists (has to extend the MovieClip class) already (i.e defined in an AS file) then that class will take on the image of the MC, if not then a new class will be created. You can then refer to it as you would any other class:

var myMC:libraryMC = new libraryMC();

Was This Post Helpful? 0
  • +
  • -

#3 Ryan1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 29-September 07

Re: How would this be done in AS3?

Posted 20 June 2009 - 09:32 AM

View PostUnknownFury, on 14 Jun, 2009 - 09:02 AM, said:

Right click the MC in the library and click linkage. You can then give it a class name. If that class exists (has to extend the MovieClip class) already (i.e defined in an AS file) then that class will take on the image of the MC, if not then a new class will be created. You can then refer to it as you would any other class:

var myMC:libraryMC = new libraryMC();


I guess I sort of understand this, but it's still not quite working right. I just let it make a new class, named Ball, and referred to it in the code. It adds the MC to the stage at the point 100, 100, but it doesn't allow the x-value to change. Here's the code I'm trying to use;

package {
	import flash.display.MovieClip;

	import flash.events.Event;

	public class Movement extends MovieClip {
		private var ball:MovieClip;

		public function Movement() {
			init();
		}
		private function init():void {
			var ball:Ball = new Ball;
			addChild(ball);
			ball.x = 100;
			ball.y = 100;
			addEventListener(Event.ENTER_FRAME,EnterFrame);
		}

		private function EnterFrame(event:Event):void {
			ball.x += 5;
		}
	}
}


I end up getting this; TypeError: Error #1009: Cannot access a property or method of a null object reference. at Movement/EnterFrame()

Sorry to be a burden, but learning AS3 isn't working out too good for me.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1