【问题标题】:how to drag and drop button to target button in flash如何将按钮拖放到Flash中的目标按钮
【发布时间】:2016-08-09 07:15:51
【问题描述】:

我想创建一个可以拖放到另一个按钮的按钮,以便将按钮位置(x, y) 拖到目标按钮的位置。 我的代码:

sejarah.onPress = function(){
     startDrag(this);}
sejarah.onRelease = function(){
     if(this.hitTest (atarget)){
       this._x = _root.atarget._x;
       this._y = _root.atarget._y;}
     else{stopDrag();}
} 

我想实现这个:http://www.thibaud.be/#

【问题讨论】:

  • 改进了海报意图的语法和清晰度。

标签: actionscript-2 flash-cs4


【解决方案1】:
on(press) {
    startDrag(this);
}

on(release) {
    stopDrag();
    _x = Math.round(_x/_width)*_width + 0;
    _y = Math.round(_y/_height)*_height + 0;
}

这是可以完成此类工作的最简单的代码之一。您将这段代码放在一个按钮中,当您停止拖动此按钮时,它的位置将捕捉到网格。

你的按钮的剪辑中心必须在按钮的左上角,否则它会变得很奇怪。此外,您可以通过将零更改为您需要的位置来更改网格的开始。

你可以画一个网格来查看附件。

【讨论】:

    猜你喜欢
    • 2019-09-06
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    • 2020-10-08
    • 1970-01-01
    相关资源
    最近更新 更多