加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flex动态添加button并添加click事件

发布时间:2020-12-15 04:46:36 所属栏目:百科 来源:网络整理
导读:?xml version="1.0" encoding="utf-8"?s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"fx:Script![CDATA[import mx.colle
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
	
	<fx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			import mx.controls.Alert;
			private var array:ArrayCollection = new ArrayCollection();
			private function addButtons():void
			{
				for(var i:int=0;i<10;i++) {
					var btn:Button = new Button();
					btn.label = "123";
					btn.id = "btn"+i.toString();
					btn.label = "btn"+i.toString();
					btn.x = 10+i*80;
					btn.y = 50;
					btn.alpha = 0.1;
					btn.addEventListener(MouseEvent.CLICK,handleClick);
					btn.addEventListener(MouseEvent.MOUSE_OVER,handleOver);
					btns.addElement(btn);
				}
			}
			
			private function handleClick(event:Event):void {
				var b:Button = event.target as Button;
				Alert.show("button的ID:"+b.id.toString());
			}
			
			private function handleOver(event:Event):void {
				var b:Button = event.target as Button;
				Alert.show("button的x坐标:"+b.x.toString());
				b.alpha = 1.0;
			}
			
			
			
			
		]]>
	</fx:Script>
	
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
	</fx:Declarations>
	
	<s:Button x="471" y="88" label="test" click="addButtons()"/>
	<s:Panel id="btns" x="35" y="148" width="834" height="243">
		
	</s:Panel>
</s:Application>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读