Here's why the statement
x.label="jim"; causes the compilation error "Access of undefined property x": A <mx:Script> is a place to declare vars and functions; you generally don't want to put bare statements there. A bare statement in an <mx:Script> doesn't do what you'd expect. Most people expect it to initialize the component in some way, but it actually becomes part of the "class constructor", which executes before any instances get created. There is no class-level (i.e., "static") property named x on this class, so your statement doesn't compile. If you comment out this line, you then get another compilation error, "Attempting to initialize inherited property 'x' of type 'Number' with value of incompatible type 'mx.controls.Button'." This is because your component inherits an instance property x from DisplayObject. When you use 'x' as the id of a component, the MXML compiler autogenerates another property named x to hold the reference to that component. Your component would have two properties named x, which isn't allowed. - Gordon ________________________________ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of pauland2513 Sent: Thursday, February 08, 2007 2:22 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: properties in components.. OK, thanks guys, I guess I do need that coffee. The problem goes away if the code is wrapped in a function (to be called on initialisation or creation complete_ - I guess thats the only way to safely access the properties since otherwise they may not exist. The thing that really threw me was that the compiler only raised objections when the component was added to the main application. Anyway, problem solved. Paul --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , "Igor Costa" <[EMAIL PROTECTED]> wrote: > > In Addition of Rich Tretola solution > > here's anothe one. > > > <yours:Component creationComplete="setLabel" id="labelfill"/> > > <script> > public function setLabel():void > { > labelfill.label = "my Label"; > } > </script> > > > Best > > On 2/8/07, Rich Tretola <[EMAIL PROTECTED]> wrote: > > > > The 1st problem is that you can not name your button id x as it is a > > reserved word. > > > > > > Not sure what you are trying to accomplish. If your goal is to be able to > > set the label from the main application, you should do something like this: > > > > > > <?xml version="1.0" encoding="utf-8"?> > > <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> " width="400" > > height="300"> > > <mx:Script> > > <![CDATA[ > > [Bindable] > > public var myLabel:String="jim"; > > ]]> > > </mx:Script> > > <mx:Button id="x1" label="{myLabel}"/> > > </mx:Canvas> > > > > > > > > <?xml version="1.0" encoding="utf-8"?> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> " > > layout="absolute" xmlns:local="*"> > > <local:Test myLabel="Rich"/> > > </mx:Application> > > > > Rich > > > > > > > > On 2/8/07, Paul Andrews < [EMAIL PROTECTED]> wrote: > > > > > > OK, this is driving me nuts. I'm using Flex Builder 2.01 on a PC. > > > > > > I have a very simple component (say test.mxml), code below, where I set > > > a > > > label value on a button using actionscript. > > > > > > I can get this to compile very simply and we're all happy. > > > > > > As soon as I edit the main application(main.mxml) to include this > > > component: > > > > > > <comp:test> > > > </comp:test> > > > > > > main.mxml is happy but now I get a compile error (access of undefined > > > property) in test.mxml saying that the button id is an undefined > > > property. > > > When I edit the test.mxml code, flexbuilder will happily give me code > > > hints > > > about the properties after I've put in the button id. > > > > > > What's going on? Maybe I just need more coffee? > > > > > > Paul > > > > > > <?xml version="1.0" encoding="utf-8"?> > > > <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml <http://www.adobe.com/2006/mxml> " width="400" > > > height="300"> > > > <mx:Script> > > > <![CDATA[ > > > x.label="jim"; > > > ]]> > > > </mx:Script> > > > <mx:Button id="x" label="fred"/> > > > </mx:Canvas> > > > > > > > > > > > > -- > > Rich Tretola > > <mx:EverythingFlex/> > > http://www.EverythingFlex.com <http://www.EverythingFlex.com> > > > > > > > > -- > ---------------------------- > Igor Costa > www.igorcosta.org > www.igorcosta.com > skype: igorpcosta >