开发者

1195: Attempted access of inaccessible method ?

hi i have this really basic class here .. and i want to use setter and getter functions but i cant access them here is my code

the class which is in a folder called classes and file name is ColorPicker.as

package classes {
    import flash.display.*;
    public class ColorPicker extends Sprite {
        private var _wi开发者_C百科dth:uint = 50;
        //private var _height:uint;
        private var BG:Shape = new Shape();

        public function ColorPicker ():void
        {
            BG.graphics.beginFill(0xFF0000);
            BG.graphics.drawRect(0, 0, 90, 90);
            BG.graphics.endFill();
            addChild(BG);

        }
        public function get Wd () :uint 
        {
            return _width; 

        }       
        public function set Wd ( h:Number) :void 
        {
            _width = h ; 

        }
    }

}

my code in time line

import classes.ColorPicker ; 
var cp:ColorPicker = new ColorPicker () ; 
trace(cp.Wd());

if i tried to access the function with out the get or the set i would have no problems .. could someone explain whats happening to me .. thanks in advance .


public function get Wd():uint declares a new property, not a function.

You access properties similar to how you'd access an attribute:

trace( cp.wd ); //will trace out the value
cp.wd = 5;
trace( cp.wd ); //should trace out 5

*"CP" has an internet cultural meaning that is likely unintended, please try to use more descriptive variable names to avoid embarrassing situations.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜