<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init()"> <mx:Style> ToolTip{ background-color:#FFCCFF; font-size:12px; } </mx:Style> <mx:Script> <![CDATA[ // 这个是画一个简单的图形并能清除他 import mx.controls.ToolTip; import mx.printing.FlexPrintJob; import printView; import mx.core.UIComponent; import mx.controls.Alert; private var _sperite:Sprite; private var _sperite2:Sprite; private var tt:ToolTip = new ToolTip(); private function init(){ _sperite = new Sprite();//建立影片精灵 _sperite2 = new Sprite();//建立影片精灵 var uicomponent:UIComponent = new UIComponent(); uicomponent.addChild(_sperite); uicomponent.addChild(_sperite2); box.addChild(uicomponent); doDraw(); } function doDraw():void{ tt.text="加饭要吃饱呀"; tt.width = 120; tt.height = 120; tt.x = 616; tt.y = 42; tt.visible = false; button1.addChild(tt); _sperite.graphics.lineStyle(1,0xA8A8A8,1); _sperite.graphics.moveTo(0,0); _sperite.graphics.lineTo(100,100); _sperite2.graphics.lineStyle(1,0xFFCC99,1); _sperite2.graphics.beginFill(0xFFCC99,1); _sperite2.graphics.drawCircle(50,50,20); _sperite2.graphics.endFill(); _sperite2.addChild(tt); _sperite2.addEventListener(MouseEvent.MOUSE_OVER,showTip); _sperite2.addEventListener(MouseEvent.MOUSE_OUT,hideTip); } function showTip(event:MouseEvent){ tt.visible = true; tt.x = event.localX; tt.y = event.localY; this.graphics.beginFill(0x6699FF,1); this.graphics.endFill(); } function hideTip(event:MouseEvent){ tt.visible = false; } function doClean():void{ _sperite2.graphics.clear(); } ]]> </mx:Script> <mx:Button x="616" y="42" label="清除" id="button1" click="doClean()"/> <mx:Canvas id="canvas" x="10" y="42" height="400" width="500" backgroundColor="#FFFFCC" > <mx:Canvas id="box" x="0" y="0" ></mx:Canvas> </mx:Canvas> <mx:Label x="147" y="16" text="这个是画一个简单的图形并能清除他" fontSize="12"/> </mx:Application>