Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-06-2012, 05:47 PM   #1
Pedz101
Registered User
 
Join Date: Aug 2012
Posts: 9
Question Error #2007: Parameter child must be non-null.

Hello I am still a newbie at actionscript class. I have no idea on what's the error. If you can please help me that would be thankful. The error says:

TypeError: Error #2007: Parameter child must be non-null.
at flash.display: : DisplayObjectContainer/addChild()
at Movement/init()


ActionScript Code:
package {     import flash.display.MovieClip;     import flash.events.Event;     import flash.events.MouseEvent     import Input;         public class Movement extends MovieClip {                 public var square:MovieClip;         public var start_btn:MovieClip                 private var _max:Number = 10;         private var dx:Number = 0;         private var dy:Number = 0;                             public function Movement():void         {             this.stop();             addEventListener(Event.ADDED_TO_STAGE, init);         }                     private function init(e:Event):void {             removeEventListener(Event.ADDED_TO_STAGE, init);                         //adding Childs             addChild(square);             addChild(start_btn);                                     //Initialize the Input.as Class with handler on stage             Input.initialize(stage);                         //Add Events Listeners             addEventListener(Event.ENTER_FRAME, refresh);             start_btn.addEventListener(MouseEvent.CLICK, startingGame);         }                 private function refresh(e:Event):void {             //Key Handler             if (Input.kd("A", "LEFT")) {                 dx = dx < 1 - _max ? _max * -1 : dx - 1;             }             if (Input.kd("D", "RIGHT")) {                 dx = dx > _max - 1 ? _max : dx + 1;             }                         if (!Input.kd("A", "LEFT", "D", "RIGHT")) {                 if (dx > 1) {                     dx = dx < 1 ? 0 : dx - 1;                 } else {                     dx = dx > -1 ? 0 : dx + 1;                 }             }                         if (Input.kd("W", "UP")) {                 dy = dy < 1 - _max ? _max * -1 : dy - 1;             }             if (Input.kd("S", "DOWN")) {                 dy = dy > _max - 1 ? _max : dy + 1;             }                         if (!Input.kd("W", "UP", "S", "DOWN")) {                 if (dy > 1) {                     dy = dy < 1 ? 0 : dy - 1;                 } else {                     dy = dy > -1 ? 0 : dy + 1;                 }             }                         //Margin detection             if (square.x - dx < -dx || square.x + dx + square.width > stage.stageWidth) {                 //x axis detection                 square.x = square.x - dx < -dx ? 0 : stage.stageWidth - square.width;                 dx *= -1;             }                          if (square.y - dy < -dy || square.y + dy + square.height > stage.stageHeight) {                 //y axis detection                 square.y = square.y - dy < -dy ? 0stage.stageHeight - square.height;                 dy *= -1;             }                         //Apply the dynamic variables             square.x += dx;             square.y += dy;         }                 public function startingGame(e:MouseEvent):void         {             gotoAndStop(2);         }     }     }
Pedz101 is offline   Reply With Quote
Old 08-06-2012, 06:12 PM   #2
thawfeek_yahya
Senior Member
 
thawfeek_yahya's Avatar
 
Join Date: Oct 2009
Location: India
Posts: 145
Send a message via Yahoo to thawfeek_yahya Send a message via Skype™ to thawfeek_yahya
Default

Welcome to the forum.

you should initialize the movie clip before using it

ie)

Quote:
public var square:MovieClip = new MovieClip();
public var start_btn:MovieClip = new MovieClip();
thawfeek_yahya is offline   Reply With Quote
Old 08-06-2012, 06:23 PM   #3
santanoa
Dual Screen Empowered
 
santanoa's Avatar
 
Join Date: Jul 2010
Location: Israel
Posts: 258
Default

Welcome,

(EDIT: First suggestion already mentioned
resuming post...
)


If you're trying to refer to mcs you put in this class from Flash, you have to name them in Flash in order to be able to access them. Then you can just write
ActionScript Code:
//adding Childs addChild(square); addChild(start_btn);

IMPORTANT: if this is true, you should not be declaring

ActionScript Code:
public var square:MovieClip; public var start_btn:MovieClip

in your class, because this will actually override your mcs' variables and you won't be able to access them


Hope something i wrote made sense

Last edited by santanoa; 08-06-2012 at 06:25 PM. Reason: thawfeek_yahya...
santanoa is offline   Reply With Quote
Old 08-06-2012, 06:54 PM   #4
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,397
Default

Post the Input class.
I have no idea what the following statement actually means.
ActionScript Code:
//Initialize the Input.as Class with handler on stage Input.initialize(stage);
[afz]snickelfitz is offline   Reply With Quote
Old 08-06-2012, 09:00 PM   #5
Pedz101
Registered User
 
Join Date: Aug 2012
Posts: 9
Default

@thawfeek_yahya:
Thanks worked out perfectly

@santanoa:
Thanks for the advice
Pedz101 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:18 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.