首页 文章

Flash Banner 中的AS3视差效果可防止Movieclip按钮运行

提问于
浏览
0

我正在制作富媒体Flash Banner 广告 . 我有3到4个圆形MovieClip按钮,可以移动AS3视差效果 . 它看起来像一个EnterFrame循环在AS3中创建效果 . 但是,当我分配MouseEvent Click事件时,单个Movieclip按钮将不起作用 . 我希望在点击MC时,视差移动停止并且播放头前进到主时间轴上的特定标签 . 我确信这可以做到,但我缺乏专业知识 . 这是代码:

//add an event listener to trigger every frame
addEventListener(Event.ENTER_FRAME, onFrame);

//set a constant that marks the centre of the stage
//the stage is 600 x 400, so we halve that
const stageCentre:Point=new Point(180,300);

//set an easing constant
const ease:Number=0.2;

function onFrame(e:Event) {
//create a point to store the distances the mouse is from the centre
var mouseOffset:Vector3D=new Vector3D(stageCentre.x-mouseX,stageCentre.y-mouse Y, 0);

//move each background layer by a different percentage of offset
//the easing constant is used here to create smoother results

//foreground moves the most; 75% of the mouse offset
clip1_mc.x+=(stageCentre.x+mouseOffset.x*0.70 - clip1_mc.x)*ease;
clip1_mc.y+=(stageCentre.y+mouseOffset.y*0.50 - clip1_mc.y)*ease;

//mid-ground moves a medium amount; 50% of the mouse offset
clip2_mc.x+=(stageCentre.x+mouseOffset.x*1.00 - clip2_mc.x)*ease;
clip2_mc.y+=(stageCentre.y+mouseOffset.y*1.00 - clip2_mc.y)*ease;

//background moves the least; 25% of mouse offset
clip3_mc.x+=(stageCentre.x+mouseOffset.x*1.75 - clip3_mc.x)*ease;
clip3_mc.y+=(stageCentre.y+mouseOffset.y*1.00 - clip3_mc.y)*ease;
}


//Click on button to go to and Play "kelsey" label (this does NOT work)

clip1_mc.kelsey_btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{
MovieClip(root).gotoAndStop("kelsey");
}

2 回答

  • 0

    确保clip1_mc位于最顶层,它可能与正在赶上鼠标单击事件的其他剪辑重叠 .

    如果所有图层中都有按钮,则需要为除按钮之外的所有内容禁用鼠标事件 . 例如,如果每个动画片段中都有“按钮”和“背景”,并且您只想保持按钮可单击,请在该动画片段中执行以下操作:

    background.mouseEnabled = false;
    background.mouseChildren = false;
    

    这样,后台将不会监听任何鼠标交互

  • 0

    鼠标单击动画片段时添加removeEventlistener

    clip1_mc.kelsey_btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
    function fl_MouseClickHandler(event:MouseEvent):void
    {
    this.removeEventListener(Event.ENTER_FRAME, onFrame);
    MovieClip(root).gotoAndStop("kelsey");
    }
    

相关问题