0

well i want this actually

<s:Button x="240" id="anything"  y="80" label="User 4" click="click_Handler(event.currentTarget.id)" />


protected function click_Handler(s:String)
{
s.width ="xx" ;
}

Well in this code of course s.width cant be done. any ideas about how to do this. i must change the width when i click on the button.

Muhammad Umar
  • 11,391
  • 21
  • 91
  • 193

1 Answers1

1

you need to use the id of the object, or pass the object reference instead of just its id to the event handler. In the example you have given the id is anything. Make sure this is unique for each object instance in the MXML.

One option is to directly refer to the stage instance. The code will be like this

protected function click_Handler(s:String){
    anything.width ="xx" ;
}

The other option is to pass either the event object (which is a good practice) or at least the target object to event handler, and use that. The code will be like this:

<s:Button x="240" id="anything"  y="80" label="User 4" click="click_Handler(event)" />

protected function click_Handler(e:Event){
    ((DisplayObject)(e.currentTarget)).width = "xx"
}
danishgoel
  • 3,650
  • 1
  • 18
  • 30
  • the point is i want to input the id to the function. what i want to do is their are lot of buttons when i click on any button its own characteristics changes. so the button will pass its id and then using its id i can do id.width ="xx" – Muhammad Umar Sep 24 '11 at 04:28
  • @umar see my edit. For this pass the `event` object and use its `currentTarget` property – danishgoel Sep 24 '11 at 04:32