The 'name' property is one way in principle to attach extra information
to an instance, but we don't recommend doing this because the Flex
framework uses the 'name' property for its own purposes.

 

In general, since most framework classes are non-dynamic, you should get
used to extending them whenever you need them to store additional
instance data.

 

- Gordon

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of We Made That design
Sent: Tuesday, November 28, 2006 1:15 PM
To: [email protected]
Subject: RE: [flexcoders] accessing variables through events

 

Thank you Gordon,

That worked great. I guess I wasnt too clear on what I wanted but you
nailed it. I was trying to add myUIComponent.i = i without extending the
UIComponent in a subclass. I came to the same conclusion by appending
the
vars to an existing property already there and realized I had to do it
your way. I was doing this at one point myUIComponent.name =
i.toString();
and I could see it coming back.

Thanks you so much.. saved me many more hours of foolishness.

Jeremy

> i is a local var of the tracePath() method; it can't be accessed
outside
> this method, and it doesn't even exist after tracePath() has finished
> executing.
>
>
>
> What you are trying to do is dynamically create N instances of a
> UIComponent, and when you click one of them, you want to know whether
it
> is the 1st, 2nd, ... one that you created. (Actually, I suspect that
> what you really want to get when you click is the 'results' data,
> because otherwise I don't know why you calculated it.)
>
>
>
> The best way to do this is to write a trivial subclass of UIComponent
> which can store 'i' and/or 'results' as an instance var of each
> UIComponent that you create:
>
>
>
> public class MyComponent extends UIComponent
>
> {
>
> public class MyComponent()
>
> {
>
> super();
>
> }
>
>
>
> public var i:int;
>
>
>
> public var results:XMLList;
>
> }
>
>
>
> Inside tracePath(), create instances of MyComponent and set 'i' and/or
> 'results' on each one:
>
>
>
> var myUIComponent:MyComponent = new MyComponent();
>
> myUIComponent.i = i;
>
> myUIComponent.results = results;
>
> myUIComponent.graphics...
>
>
>
> Then inside mouseClickHandler() you can access 'i' and 'results' as
> event.currentTarget.i and event.currentTarget.results. You can't
access
> them as this.i and this.results because 'this' is always whatever
> component or application your <mx:Script> is inside of; it isn't the
> object that dispatched or listened to the MouseEvent.
>
>
>
> BTW, you could probably accomplish of all this more easily by using
the
> <mx:Repeater> tag, but that's another topic.
>
>
>
> - Gordon
>
>
>
> ________________________________
>
> From: [email protected] <mailto:flexcoders%40yahoogroups.com>
[mailto:[email protected] <mailto:flexcoders%40yahoogroups.com>
] On
> Behalf Of Jeremy Tooley
> Sent: Monday, November 27, 2006 7:46 PM
> To: [email protected] <mailto:flexcoders%40yahoogroups.com> 
> Subject: [flexcoders] accessing variables through events
>
>
>
> Quick question regarding accessing variables.
>
> I have the following code
>
> public function tracePath():void {
>
> for (var i:int = 0; i < photoFeed.menu.submenu.length(); i++) {
> trace([EMAIL PROTECTED])
> var results:XMLList =
> [EMAIL PROTECTED];
> trace(results);
> trace (i);
> var myUIComponent:UIComponent = new UIComponent();
>
> myUIComponent.graphics.beginFill(0xFFCC00);
> myUIComponent.graphics.drawCircle(60*i, 30, 30);
> myUIComponent.buttonMode = true;
> myUIComponent.useHandCursor = true;
> myUIComponent.addEventListener(MouseEvent.CLICK,
> mouseClickHandler);
>
> this.addChild(myUIComponent);
>
> }
> trace(photoFeed.menu.submenu.length() +"hello");
> }
>
> and I access using this function
> public function mouseClickHandler(event:MouseEvent):void{
> trace(this.i);
> }
>
> My question is... how do I access the "i" variable from within the
> mouseClickHandler() function
> so I could find out certain properties. The above code does not seem
to
> find the "i" based on the dynamically created component.
>
> I really want to be able to find out the list collection based on
click.
>
> Thanks
> Jeremy
>
>
>
>

Jeremy Tooley
Creative Director
We Made That Design Group Inc.
[EMAIL PROTECTED] <mailto:jeremy%40wemadethat.com> 
http://www.wemadethat.com <http://www.wemadethat.com> 
p: 403.668.0857
c: 403.836.3048

 

Reply via email to