--- In flexcoders@yahoogroups.com, "mattjshannon" <[EMAIL PROTECTED]> wrote: > > Hi, I'm new to flex and actionscript - having a java background. > > I keep getting a 1195 compiler error when trying to invoke what i > believe is a public non-static method from a singleton class instance. > > Here is a cut-down version of the code that demonstrates the problem, > along with accompanying error ... (Flex 2.0.1) > > Error: > 1195: Attempted access of inaccessible method name through a > reference with static type test:ATest. > > Invoker.mxml :- > > <?xml version="1.0" encoding="utf-8"?> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > layout="absolute" creationComplete="onCreationComplete()"> > <mx:Script> > <![CDATA[ > import test.ATest; > > private function onCreationComplete() : void > { > var tst : ATest = ATest.getInstance(); > tst.name("XXX"); // << this call fails > // tst._name="XXX"; // << this call works > } > ]]> > </mx:Script> > <mx:Label text="{tst.name}"/> > </mx:Application> > > > > ATest.as :- > > // ActionScript file > package test > { > public class ATest > { > private static var instance : ATest; > > public function ATest() > { > if (instance != null) > { > throw new Error("Singleton Exception"); > } > instance = this; > } > > public static function getInstance() : ATest > { > if (instance == null) > { > instance = new ATest(); > } > return instance; > } > > public function set name(__name : String) : void > { > _name = __name; > > } > > public function get name() : String > { > return _name; > } > > public var _name : String; > } > } > > Is there something tricky going on with these set/get methods? > > thanks > > Matt. >
When you declare your "name" method with the "set" or "get" keywords, it will be automatically called when you read from or assign to "tst.name", using a syntax like tst.name="XXX". Cosma