A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] problems with setter/getter in AS 3.0

  1. #1
    Junior Member
    Join Date
    Sep 2007
    Posts
    2

    resolved [RESOLVED] problems with setter/getter in AS 3.0

    hi everyone

    i'm trying to convert an AS 2.0 component to an AS 3.0 component but i'm having some problems with getter and setter methods.

    here is something similar to what i'm trying to do:

    this component has only one variable, _path. in the component inspector i give my variable the value "myFile"


    the AS 2.0 component is working fine


    Code:
    class as2Class extends MovieClip{
                
        private var _path:String;
        
        [Inspectable(defaultValue="", type=String, name="file path")]
        public function set path(value:String):Void{
            _path = value;
            trace("set")
        }
        public function get path():String{
            return _path;
        }
        public function as2Class(){
            trace(_path);
            trace("constructor")
        }
    }
    if i test the component in the output panel i get :
    set
    myFile
    constructor

    but the AS 3.0 component isn't working


    Code:
    package{
        import flash.display.MovieClip;
        
        public class as3Class extends MovieClip{
                
            private var _path:String;
        
            [Inspectable(defaultValue="", type=String, name="file path")]
            public function set path(value:String):void{
                _path = value;
                trace("set")
            }
            public function get path():String{
                return _path;
            }
            public function as3Class(){
                trace(_path);
                trace("constructor")
            }
        }
    }
    if i test this component, in the output panel i get:
    null
    constructor
    set

    why isn't the as3 component working like the as2 component? and how could i
    fix this problem?

    Thank you.
    Attached Files Attached Files

  2. #2
    Senior Member cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    You need to add an Eventdispatcher first.

    PHP Code:
    public function as3Class ()
            {
                
    trace ("constructor");
                
    init();
            }
            private function 
    init():void
            
    {
                
    this.addEventListener(Event.ACTIVATEaddedHandler);
            }
            private function 
    addedHandler(e:Event):void
            
    {
                
    trace (path);
                
    e.target.removeEventListener(Event.ACTIVATEaddedHandler);
            } 
    ACTIVATE is dispatched when Flash Player becomes active. You are calling the getter from within the constructor.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Junior Member
    Join Date
    Sep 2007
    Posts
    2

    resolved

    thanks a lot. it works fine now.

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