dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: 1120: Access of undefined property

  1. #1
    infidel! 0vidiu's Avatar
    Join Date
    Mar 2003
    Location
    ROmania
    Posts
    267

    1120: Access of undefined property

    Hello,

    Can you please explain why the trace statement is working only if it is placed inside the constructor, "addBg" or "addSquare" functions?

    The way the code is written now gives the following error:
    1120: Access of undefined property bg_mc.


    main.as is the document class and here is the code:

    Code:
    package  
    {
    	import flash.display.MovieClip;
    	
    	/**
    	 * ...
    	 * @author infidel - aka Ovidiu Gheorghe
    	 */
    	public class main extends MovieClip
    	{
    		public var bg_mc:bg = new bg();
    		public var square_mc:square = new square();
    		
    		public function main() 
    		{
    			addBg();
    			addSquare();
    		}
    		
    		private function addSquare():void
    		{
    			bg_mc.addChild(square_mc);
    		}
    		
    		private function addBg():void
    		{
    			addChild(bg_mc);
    		}
    		
    		trace(bg_mc.x);
    	}
    	
    }
    Tnx a lot!

  2. #2
    a.k.a gltovar deadlock32's Avatar
    Join Date
    May 2001
    Location
    Naperville,IL
    Posts
    489
    your trace: trace(bg_mc.x);


    happens out side of a function in this class. try moving the trace right after you addChild it.

    -edit-

    you can only have code in the functions when in a class, other than var declarations. its just the syntax of AS3 and ECMA-script 4.

    if you notice coding in a flash timeline, you don't define public or private. its because you are coding in a function in a class with in the time line, you just don't see any of that declarations. Seems kinda wierd to explain, since it feels like a parent saying ' that just the way it is '

    Code:
    package
       class
         class variables    
         class function    
              local variables
              local functions
    Last edited by deadlock32; 06-04-2009 at 07:18 PM.

  3. #3
    infidel! 0vidiu's Avatar
    Join Date
    Mar 2003
    Location
    ROmania
    Posts
    267
    I'm a newbie in AS3 So everything inside a class should be organized in functions, right?

    Tnx, this version of the code works fine now:

    Code:
    package  
    {
    	import flash.display.MovieClip;
    	
    	/**
    	 * ...
    	 * @author infidel - aka Ovidiu Gheorghe
    	 */
    	public class main extends MovieClip
    	{
    		public var bg_mc:bg = new bg();
    		public var square_mc:square = new square();
    		
    		public function main() 
    		{
    			addBg();
    			addSquare();
    			
    			outputTrace();
    		}
    		
    		private function addSquare():void
    		{
    			bg_mc.addChild(square_mc);
    		}
    		
    		private function addBg():void
    		{
    			addChild(bg_mc);
    		}
    		
    		private function outputTrace():void
    		{
    			trace(bg_mc.x);
    		}
    		
    	}
    	
    }
    Tnx again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center