00:00
00:00
Newgrounds Background Image Theme

markololohands 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!

Modify flash object in Actionscript

428 Views | 4 Replies
New Topic Respond to this Topic

Hi, I have just started learning flash and actionscript and would appreciate help with a small issue. I know some Java and C++ but I'm a total begginer here. I was trying to copy the game shown in this video (http://www.youtube.com/watch?v=sK2LEbznMb4), so I created a flash file with a circle, converted it to a Symbol called "ball" of a class "Ball", and tried to modify it from an Actionscript file. However, in the line I try to modify "ball.x" , I get "Error 1009: Cannot access a property or method of a null object reference", which means "ball" is null.

How do I tell ActionScript that I am referring to the "ball" object I already created in the flash file? The guy in the video didn't initialize the variable or anything.

Here is the whole code of the .as file (the circle should fall):

package
{
	import flash.display.MovieClip
	import flash.events.Event
	
	public class Project extends MovieClip
	{
		public var ball:Ball;
		
		public function Project():void
		{
			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
		}
		
		private function enterFrameHandler(e:Event):void
		{
			ball.y += 1;
		}
	}
}

The files are called "Project.fla" and "Project.as", and they're in the same folder.
Thanks in advance!

Response to Modify flash object in Actionscript 2013-09-06 16:12:50


At 9/6/13 03:44 PM, Brunogi wrote: How do I tell ActionScript that I am referring to the "ball" object I already created in the flash file? The guy in the video didn't initialize the variable or anything.

If ball is an instance name, just refer to it like that. Otherwise, you have to create a new Ball().

Response to Modify flash object in Actionscript 2013-09-06 16:38:28


At 9/6/13 04:12 PM, MSGhero wrote:
At 9/6/13 03:44 PM, Brunogi wrote: How do I tell ActionScript that I am referring to the "ball" object I already created in the flash file? The guy in the video didn't initialize the variable or anything.
If ball is an instance name, just refer to it like that. Otherwise, you have to create a new Ball().

Yes, when I try to access its attributes (ball.x) I do it for the "ball" object I created. But "ball" is null while it should be a reference to the circle I created in the .fla graphic editor.

Response to Modify flash object in Actionscript 2013-09-06 16:48:11


At 9/6/13 04:38 PM, Brunogi wrote: Yes, when I try to access its attributes (ball.x) I do it for the "ball" object I created. But "ball" is null while it should be a reference to the circle I created in the .fla graphic editor.

Did you give it an instance name? If not do that. Or just instantiate the ball like I said.

Response to Modify flash object in Actionscript 2013-09-06 17:32:21


At 9/6/13 04:48 PM, MSGhero wrote:
At 9/6/13 04:38 PM, Brunogi wrote: Yes, when I try to access its attributes (ball.x) I do it for the "ball" object I created. But "ball" is null while it should be a reference to the circle I created in the .fla graphic editor.
Did you give it an instance name? If not do that. Or just instantiate the ball like I said.

Ah, that was the problem. I thought the instance name would be the name I typed in the "Convert to Symbol" window, but I had left blank the actual "Instance name" field in the editor.
Thanks a lot!