开发者

Using the identifier of an object to change settings in flex

开发者 https://www.devze.com 2023-04-08 15:34 出处:网络
well i want this actually <s:Button x=\"240\" id=\"anything\"y=\"80\" label=\"User 4\" click=\"click_Handler(event.currentTarget.id)\" />

well i want this actually

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


protected func开发者_JAVA技巧tion 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.


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"
}
0

精彩评论

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

关注公众号