A Flash Developer Resource Site

Results 1 to 3 of 3

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

Threaded View

  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

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