我有這組驗證碼之前和形象探寶後創建一個簡單的:如何使用此代碼實現globalToLocal?
import com.greensock.*;
import com.greensock.easing.*;
function init() : void {
sliderbar_mc.buttonMode = true;
sliderbar_mc.addEventListener(MouseEvent.MOUSE_DOWN,moveSliderbar);
stage.addEventListener(MouseEvent.MOUSE_UP,stopSliderbar);
mask_mc.alpha = 0;
after_mc.mask = mask_mc;
TweenLite.to(sliderbar_mc,4,{x:stage.stageWidth/2,ease:Elastic.easeOut});
TweenLite.to(mask_mc,4,{x:stage.stageWidth/2,ease:Elastic.easeOut});
}
function moveSliderbar(event:MouseEvent):void {
stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
}
function stopSliderbar(event:MouseEvent):void{
stage.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
}
function mouseMoveHandler(event:MouseEvent):void{
sliderbar_mc.x = mouseX;
if (sliderbar_mc.x > stage.stageWidth){
sliderbar_mc.x = stage.stageWidth;
}
else if(sliderbar_mc.x < 0){
sliderbar_mc.x = 0;
}
mask_mc.x = sliderbar_mc.x;
}
init();
但現在我需要把探寶區到舞臺上的自己的地方的電影剪輯,爲我的生活我無法弄清楚如何使用globalToLocal使這項工作......這是我的嘗試:
import com.greensock.*;
import com.greensock.easing.*;
function init():void {
area_mc.sliderbar_mc.buttonMode = true;
area_mc.sliderbar_mc.addEventListener(MouseEvent.MOUSE_DOWN,moveSliderbar);
stage.addEventListener(MouseEvent.MOUSE_UP,stopSliderbar);
area_mc.mask_mc.alpha = 0;
area_mc.after_mc.mask = area_mc.mask_mc;
TweenLite.to(area_mc.sliderbar_mc,3,{x:stage.stageWidth/2,ease:Elastic.easeOut});
TweenLite.to(area_mc.mask_mc,3,{x:stage.stageWidth/2,ease:Elastic.easeOut});
}
function moveSliderbar(event:MouseEvent):void {
stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
}
function stopSliderbar(event:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoveHandler);
}
function mouseMoveHandler(event:MouseEvent):void {
var topLeft:Point = area_mc.localToGlobal(new Point(0, 0));
var bottomRight:Point = area_mc.localToGlobal(new Point(width, height));
area_mc.sliderbar_mc.x = area_mc.mouseX;
if (area_mc.mouseX > topLeft.x) {
area_mc.sliderbar_mc.x = topLeft.x;
}
else if(area_mc.mouseX < bottomRight.x){
area_mc.sliderbar_mc.x = bottomRight.x;
}
area_mc.mask_mc.x = area_mc.sliderbar_mc.x;
}
init();
顯然,這是不正常的,我知道這一切都在mouseMoveHandler功能,可有人請給我一些指針?
你的mouseMoveHandler中的代碼很混亂。你能解釋你想做什麼嗎? – prototypical 2011-05-18 00:47:16