Flex 画线的方法.
public var lines1 :flash.display.Sprite = new Sprite (); //
来自:http://www.cnblogs.com/wingfay/archive/2008/02/29/1086075.html
lines1.graphics.lineStyle(2,0x0099ff,1);//设置颜色 粗细
lines1.graphics.moveTo(uFrom.x+uFrom.width/2,uFrom.y+uFrom.height/2); //从某个坐标开始
lines1.graphics.lineTo(uTo.x+uTo.width/2,uTo.y+uTo.height/2); //画到某个坐标
//因为addChild方法 不能识别 非继承mc.core.UIComponent的控件 所以先声明一个组件 把控件放进去然后在放进界面中
var comp: UIComponent = new UIComponent();
comp.addChild(lines);
addChild(comp);
再flex 3 IDE Flex Builder 3 beta 3下编译通过
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" borderColor="#FFFFFF" >
<mx:Script>
<![CDATA[
import mx.effects.Move;
import mx.controls.*;
import mx.core.*;
import mx.effects.*;
public var lines :Sprite = new Sprite ();
public var lines1 :flash.display.Sprite = new Sprite ();
public function TestPaint():void
{
//Alert.show("Hello World!");
lines.graphics.lineStyle(2,0x0099ff,1);
DrawLine(lines,lbl,btn1);
DrawLine(lines,lbl,btn2);
DrawLine(lines,lbl,btn3);
var comp: UIComponent = new UIComponent();
comp.addChild(lines);
addChild(comp);
}
public function DrawLine(lines:Sprite,uFrom:UIComponent,uTo:UIComponent):void
{
lines.graphics.moveTo(uFrom.x+uFrom.width/2,uFrom.y+uFrom.height/2);
lines.graphics.lineTo(uTo.x+uTo.width/2,uTo.y+uTo.height/2);
}
public function btn1_mouseOver(event:Event):void
{
lines1.graphics.lineStyle(2,0xd43dd6,1);
DrawLine(lines1,btn1,btn2);
DrawLine(lines1,btn1,lbl);
var comp: UIComponent = new UIComponent();
comp.addChild(lines1);
addChild(comp);
}
public function btn1_mouseOut(event:Event):void
{
lines1.graphics.clear();
DrawLine(lines,lbl,btn1);
}
public function Testmove():void
{
var move:Move = new Move();
if(btn2.x!=lbl.x)
{
move.target=btn2;
move.end();
move.xTo=lbl.x;
move.yTo=lbl.y;
move.play();
}
else
{
move.target=btn2;
move.end();
move.xTo=340;
move.yTo=104;
move.play();
}
}
]]>
</mx:Script>
<mx:Button x="176" y="34" label="btn1" id="btn1" mouseOver="btn1_mouseOver(event)" mouseOut="btn1_mouseOut(event)"/>
<mx:Button x="340" y="104" label="btn4" id="btn2"/>
<mx:Button x="53" y="167" label="btn3" id="btn3"/>
<mx:Button x="131" y="373" label="Paint" click="TestPaint()"/>
<mx:Label x="176" y="169" text="LblMiddle" width="71" height="20" id="lbl"/>
<mx:Button x="303" y="324" label="Move" click="Testmove()"/>
</mx:Application>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" borderColor="#FFFFFF" >
<mx:Script>
<![CDATA[
import mx.effects.Move;
import mx.controls.*;
import mx.core.*;
import mx.effects.*;
public var lines :Sprite = new Sprite ();
public var lines1 :flash.display.Sprite = new Sprite ();
public function TestPaint():void
{
//Alert.show("Hello World!");
lines.graphics.lineStyle(2,0x0099ff,1);
DrawLine(lines,lbl,btn1);
DrawLine(lines,lbl,btn2);
DrawLine(lines,lbl,btn3);
var comp: UIComponent = new UIComponent();
comp.addChild(lines);
addChild(comp);
}
public function DrawLine(lines:Sprite,uFrom:UIComponent,uTo:UIComponent):void
{
lines.graphics.moveTo(uFrom.x+uFrom.width/2,uFrom.y+uFrom.height/2);
lines.graphics.lineTo(uTo.x+uTo.width/2,uTo.y+uTo.height/2);
}
public function btn1_mouseOver(event:Event):void
{
lines1.graphics.lineStyle(2,0xd43dd6,1);
DrawLine(lines1,btn1,btn2);
DrawLine(lines1,btn1,lbl);
var comp: UIComponent = new UIComponent();
comp.addChild(lines1);
addChild(comp);
}
public function btn1_mouseOut(event:Event):void
{
lines1.graphics.clear();
DrawLine(lines,lbl,btn1);
}
public function Testmove():void
{
var move:Move = new Move();
if(btn2.x!=lbl.x)
{
move.target=btn2;
move.end();
move.xTo=lbl.x;
move.yTo=lbl.y;
move.play();
}
else
{
move.target=btn2;
move.end();
move.xTo=340;
move.yTo=104;
move.play();
}
}
]]>
</mx:Script>
<mx:Button x="176" y="34" label="btn1" id="btn1" mouseOver="btn1_mouseOver(event)" mouseOut="btn1_mouseOut(event)"/>
<mx:Button x="340" y="104" label="btn4" id="btn2"/>
<mx:Button x="53" y="167" label="btn3" id="btn3"/>
<mx:Button x="131" y="373" label="Paint" click="TestPaint()"/>
<mx:Label x="176" y="169" text="LblMiddle" width="71" height="20" id="lbl"/>
<mx:Button x="303" y="324" label="Move" click="Testmove()"/>
</mx:Application>
来自:http://www.cnblogs.com/wingfay/archive/2008/02/29/1086075.html