註冊點動態改變

來源:互聯網
上載者:User

 

從別人的空間裡得到這個方法的~發現的確可以~雖然說是動態改變註冊點,實則並沒有~只是運動了mc中的座標以做到相似的效果,

start_btn:開始轉動按鈕

stop_btn:停止轉動按鈕

a_mc:一個矩形(註冊點位於中央)

a_mc.aa: 一個十字,(記錄a_mc註冊點)

 

 

 

var t:Timer = new Timer(50);//設定轉動的間隔<br />t.addEventListener(TimerEvent.TIMER,ontimer);//添加接聽程式<br />this.start_btn.addEventListener(MouseEvent.CLICK,onstart);//當開始按鈕被按下<br />function onstart(event:MouseEvent):void{<br /> t.start();//開始轉動<br />}<br />this.stop_btn.addEventListener(MouseEvent.CLICK,onstop);//當停止按鈕被按下<br />function onstop(event:MouseEvent):void{<br /> t.stop();//停止轉動<br />}<br />function ontimer(event:TimerEvent):void{<br /> this.a_mc.rotation+=5;//每50毫秒角度+5<br />}<br />this.a_mc.addEventListener(MouseEvent.CLICK,onaclick);//當中間的矩形被點擊時<br />function onaclick(event:MouseEvent):void{<br /> my(this.a_mc,new Point(this.a_mc.mouseX,this.a_mc.mouseY))//更改假象註冊點<br />}</p><p>var mc:MovieClip;//儲存被點擊的矩形<br />var p:Point;//儲存點擊的點<br />function my(m:MovieClip,point:Point):void{<br /> mc = m;<br /> p = point;<br /> RegPoint();//更改假象註冊點<br />}</p><p>function RegPoint():void {<br /> var tmp_point:Point=mc.parent.globalToLocal(mc.localToGlobal(p));//先把mc的本地座標轉化為全域座標,再把這個全域座標轉化為mc的parent的本地座標,作為新的註冊點<br /> var len:int=mc.numChildren;//記錄mc有多少個顯示對象<br /> while (len--) {<br /> var tmp_obj:DisplayObject=mc.getChildAt(len);<br /> if(tmp_obj.name!="aa"){//除了aa,其餘顯示對象均移動p.x,p.y,aa用於記錄(mc的座標的改變),註冊點的改變其實是mc裡面顯示對象的座標改變而已,實則沒有改變註冊點<br /> tmp_obj.x-=p.x;<br /> tmp_obj.y-=p.y;<br /> }<br /> }<br /> mc.x=tmp_point.x;//mc的座標根據全域座標改變<br /> mc.y=tmp_point.y;<br />}</p><p>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.