A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Access of Undefined Property from a Class

  1. #1
    Senior Member
    Join Date
    Apr 2007
    Posts
    269

    Lightbulb Access of Undefined Property from a Class

    PHP Code:
    package {
        
    import flash.display.MovieClip;
        
    import flash.events.Event;

        public class 
    DumbClass extends MovieClip {
        
            var 
    dumbXS:Number 0;
            var 
    dumbYS:Number 0;
            var 
    dumbACC:Number 0.6;
            var 
    dumbDEC:Number 0.92;
            
            public function 
    DumbClass() {
                
    this.addEventListener(Event.ENTER_FRAMEDumbMove);
            }

            public function 
    DumbMove(evt:Event):void {
                
    //Increases Speed
                
    this.+= dumbXS;
                
    this.+= dumbYS;
                
    //Reference to a MovieClip on stage called "user".
                
    if (user.this.y) {
                    
    dumbYS -= dumbACC;
                }
                
    //Reference to a MovieClip on stage called "user".
                
    if (user.this.y) {
                    
    dumbYS += dumbACC;
                }
                
    //Reference to a MovieClip on stage called "user".
                
    if (user.this.x) {
                    
    dumbXS -= dumbACC;
                }
                
    //Reference to a MovieClip on stage called "user".
                
    if (user.this.x) {
                    
    dumbXS += dumbACC;
                }
                
    ///Decrease Speed
                
    dumbYS *= dumbDEC;
                
    dumbXS *= dumbDEC;
            }
        }

    I get an error that "user" is an undefined property even though its on the stage any ideas how I can fix this? :crying:

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    You need to declare it as a public variable first. Also it is a good habit to always add the attributes public and private even Flash does it for you. It helps the compiler and helps you later when you need to debug.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Senior Member
    Join Date
    Apr 2007
    Posts
    269
    How would I go about that?

  4. #4
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    public class DumbClass extends MovieClip {
    public var user:MovieClip;
    var dumbXS:Number = 0;

    My guess is that user is a MovieClip.
    - The right of the People to create Flash movies shall not be infringed. -

  5. #5
    Senior Member
    Join Date
    Apr 2007
    Posts
    269
    Yes the user is a a MC with the instance "user" on stage. The idea is that when ever space is pressed a instance of the class is created on the stage. But from within the class it cannot seem to get the user.x/y value.

    Thats how they spawn atm.

    PHP Code:
    function spawnCircle() {
        var 
    screen_side:Number Math.round(Math.random()* 3);
        var 
    DumbTarget:DumbClass = new DumbClass();
        
    //this["dumbTarget" + dumbLoop] = dumbTemp;
        
    addChild(DumbTarget);
        if (
    screen_side == 0) {
            
    DumbTarget.= -15;
            
    DumbTarget.= -15;
        }
        if (
    screen_side == 1) {
            
    DumbTarget.815;
            
    DumbTarget.= -15;
        }
        if (
    screen_side == 2) {
            
    DumbTarget.815;
            
    DumbTarget.615;
        }
        if (
    screen_side == 3) {
            
    DumbTarget.= -15;
            
    DumbTarget.615;
        }

    I tried
    public var user:MovieClip;

    and

    public var user:MovieClip = new user_lib; (Because user_lib is the AS Esport name for the MC "user")

    Fact is I want to be able to tell the class where on stage the MC "user" is but when ever I use user (because that's its instance name on stage) it sees it as an undefined property.

  6. #6
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    try
    public var user:user_lib;
    - The right of the People to create Flash movies shall not be infringed. -

  7. #7
    Senior Member
    Join Date
    Apr 2007
    Posts
    269
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    PHP Code:
    package {
        
    import flash.display.MovieClip;
        
    import flash.events.Event;

        public class 
    DumbClass extends MovieClip {
            
            public var 
    user:user_lib;
            var 
    dumbXS:Number 0;
            var 
    dumbYS:Number 0;
            var 
    dumbACC:Number 0.6;
            var 
    dumbDEC:Number 0.92;
            
            public function 
    DumbClass() {
                
    this.addEventListener(Event.ENTER_FRAMEDumbMove);
            }

            public function 
    DumbMove(evt:Event):void {
                
    //Increases Speed
                
    this.+= dumbXS;
                
    this.+= dumbYS;
                
    //Reference to a MovieClip on stage called "user".
                
    if (user.this.y) {
                    
    dumbYS -= dumbACC;
                }
                
    //Reference to a MovieClip on stage called "user".
                
    if (user.this.y) {
                    
    dumbYS += dumbACC;
                }
                
    //Reference to a MovieClip on stage called "user".
                
    if (user.this.x) {
                    
    dumbXS -= dumbACC;
                }
                
    //Reference to a MovieClip on stage called "user".
                
    if (user.this.x) {
                    
    dumbXS += dumbACC;
                }
                
    ///Decrease Speed
                
    dumbYS *= dumbDEC;
                
    dumbXS *= dumbDEC;
            }
        }

    I heard I have to use a property manager or constructor but I have no idea which either of them are.

  8. #8
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Is the class your Document class?
    - The right of the People to create Flash movies shall not be infringed. -

  9. #9
    Senior Member
    Join Date
    Apr 2007
    Posts
    269
    No its associated with an MC in the main .fla's library. I've attached the project directory.
    Attached Files Attached Files

  10. #10
    Senior Member
    Join Date
    Apr 2007
    Posts
    269
    bump

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