localToGlobal空間座標轉換
<?xml version="1.0" encoding="utf-8"?>
<mx:Application applicationComplete="init();" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
private function init():void
{
trace("x="+contrastA.x +" , "+"y="+contrastA.y); //0,0
trace("x="+contrastB.x +" , "+"y="+contrastB.y); //0,0
trace("x="+contrastC.x +" , "+"y="+contrastC.y); //0,0
trace("-----------");
var p1:Point , p2:Point , p3:Point;
/**以cnsX容器內的空間座標,來對轉換成相對應於Global空間座標上**/
//casX上的點(x,y)
p1 = cns1.localToGlobal(new Point(5,5));
p2 = cns2.localToGlobal(new Point(0,0));
p3 = cns3.localToGlobal(new Point(0,0));
trace("p1("+p1.x + "," + p1.y + ")");
trace("p1("+p2.x + "," + p2.y + ")");
trace("p1("+p3.x + "," + p3.y + ")");
//使用p2座標給予contrast來做驗證
contrastA.x = p1.x;
contrastA.y = p1.y;
contrastB.x = p2.x;
contrastB.y = p2.y;
contrastC.x = p3.x;
contrastC.y = p3.y;
}
]]>
</mx:Script>
<mx:Canvas id="cns1" width="300" height="300" x="100" y="100" backgroundColor="#ff0000" alpha="0.6" clipContent="false">
<mx:Canvas id="cns2" width="200" height="200" x="50" y="50" backgroundColor="#00ff00" alpha="0.6" clipContent="false">
<mx:Canvas id="cns3" width="100" height="100" x="40" y="60" backgroundColor="#0000ff" alpha="0.6" />
</mx:Canvas>
</mx:Canvas>
<!--以下驗證canvas於Stage空間上-->
<mx:Canvas id="contrastA" width="50" height="30" backgroundColor="#ff0000"/>
<mx:Canvas id="contrastB" width="50" height="30" backgroundColor="#00ff00"/>
<mx:Canvas id="contrastC" width="50" height="30" backgroundColor="#0000ff"/>
</mx:Application>
沒有留言:
張貼留言