as3拖动滚动条控制小球大小

import flash.geom.Rectangle;
var left:Number=mc.back.x;
var right:Number=mc.back.width-mc.drug.width;
stage.addEventListener(MouseEvent.MOUSE_UP,stopdrag);
mc.drug.addEventListener(MouseEvent.MOUSE_DOWN,startdrag);
function startdrag(event:MouseEvent):void {
var rect:Rectangle=new Rectangle(left,0,right,0);
mc.drug.startDrag(false,rect);
}
function stopdrag(event:MouseEvent):void {
//trace(event.currentTarget.x/292);
mc.drug.stopDrag();
ball.scaleY=ball.scaleX=mc.drug.x/292;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MATLAB_GUI控制小球加减速运动 btn.start.m function btn_start() global hball ipos delt isforward npos ispaused x y ispaused = false; while (1) set(hball, 'xdata', x(ipos), 'ydata', y(ipos)); drawnow; pause(delt); ipos = ipos-(-1)^isforward; if ipos==npos+1 ipos = 1; elseif ipos == 0 ipos = npos; end if ispaused break end end ball.m hfigure = figure('name', '控制小球运动 ver 1.0', 'menubar', 'none', 'numbertitle', 'off', 'position', [600 200 350 400], 'visible', 'off'); global hball ipos delt isforward npos ispaused x y haxes = axes('position', [0.25 0.45 0.5 0.5], 'visible', 'off'); axis equal t = 0:0.1:2*pi+0.1; x = sin(t); y = cos(t); line(x, y, 'linewidth', 2); set(0, 'defaultuicontrolbackgroundcolor', get(hfigure, 'color')); set(0, 'defaultuicontrolfontsize', 12); set(0, 'defaultuicontrolunits', 'points'); hball = line('xdata', 0, 'ydata', 1, 'marker', 'o', 'markerfacecolor', 'r', 'markersize', 15); npos = length(t); ipos = 1; delt = 0.01; ispaused = false; isforward = true; uicontrol('string', '开始', 'position', [30 50 50 20], 'callback', 'btn_start;'); uicontrol('string', '停止', 'position', [100 50 50 20], 'callback', 'ispaused = true;'); uicontrol('string', '换向', 'position', [170 50 50 20], 'callback', 'isforward = ~isforward;'); uicontrol('string', '退出', 'position', [100 20 50 20], 'callback', ['ispaused = true;', 'closereq;', ... 'clear delt hball ipos ispaused t y haxes hfigure isforward npos x;']); uicontrol('style', 'slider', 'value', 0.5, 'position', [40 90 190 15], 'callback', 'delt = get(gcbo, ''value'')/100+0.01;'); uicontrol('style', 'text', 'position', [40 110 190 20], 'fontsize', 12, 'string', 'speed'); % newicon = javax.swing.imageicon('1.png'); % figframe = get(hfigure, 'javaframe'); % figframe.setfigureicon(newicon); set(hfigure, 'visible', 'on');
以下是 AS3 中实现鼠标拖动滚动图片框的基本流程: 1.创建一个包含多个图片的滚动容器,并将其添加到舞台上。 2.添加一个鼠标事件侦听器,以便在鼠标按下时开始拖动滚动容器。在鼠标移动时,更新容器的位置,以便其始终始终与鼠标指针保持同步。 3.为了确保滚动容器在边缘处停止滚动,需要添加一些边缘检测代码。如果滚动容器超出了其可见区域,则需要将其移动回可见区域内。 以下是代码示例: ``` //创建一个滚动容器 var scrollContainer:Sprite = new Sprite(); addChild(scrollContainer); //添加多个图片到滚动容器中,位置随意 var image1:Bitmap = new Bitmap(new BitmapData(200, 200, false, 0xFF0000)); scrollContainer.addChild(image1); image1.x = 0; image1.y = 0; var image2:Bitmap = new Bitmap(new BitmapData(200, 200, false, 0x00FF00)); scrollContainer.addChild(image2); image2.x = 200; image2.y = 0; var image3:Bitmap = new Bitmap(new BitmapData(200, 200, false, 0x0000FF)); scrollContainer.addChild(image3); image3.x = 400; image3.y = 0; //添加鼠标事件侦听器 scrollContainer.addEventListener(MouseEvent.MOUSE_DOWN, startScroll); scrollContainer.addEventListener(MouseEvent.MOUSE_UP, stopScroll); //设置滚动容器的边界 var maxScrollX:Number = stage.stageWidth - scrollContainer.width; var minScrollX:Number = 0; var maxScrollY:Number = stage.stageHeight - scrollContainer.height; var minScrollY:Number = 0; //开始拖动滚动容器 function startScroll(event:MouseEvent):void { scrollContainer.startDrag(false, new Rectangle(maxScrollX, maxScrollY, -maxScrollX, -maxScrollY)); } //停止拖动滚动容器 function stopScroll(event:MouseEvent):void { scrollContainer.stopDrag(); } //更新滚动容器的位置 stage.addEventListener(Event.ENTER_FRAME, updateScroll); function updateScroll(event:Event):void { //根据鼠标位置计算滚动容器的新位置 var scrollX:Number = scrollContainer.x + (stage.mouseX - scrollContainer.x) / 5; var scrollY:Number = scrollContainer.y + (stage.mouseY - scrollContainer.y) / 5; //检测滚动容器是否超出边界 if (scrollX > minScrollX) { scrollX = minScrollX; } else if (scrollX < maxScrollX) { scrollX = maxScrollX; } if (scrollY > minScrollY) { scrollY = minScrollY; } else if (scrollY < maxScrollY) { scrollY = maxScrollY; } //更新滚动容器的位置 scrollContainer.x = scrollX; scrollContainer.y = scrollY; } ``` 以上代码实现了一个基本的鼠标拖动滚动图片框的效果。你可以在此基础上进行修改和扩展,以满足具体需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值