In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

円とボタンと位置関係

下にあるボタン(バー的なもの)は上下に動きます。動かすと上で移動している円の位置にも変化が起きます。コード内容は思いつきで書いているので無茶苦茶です…。
Get Adobe Flash player
by yuugurenote 29 May 2011
    Embed
/**
 * Copyright yuugurenote ( http://wonderfl.net/user/yuugurenote )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/zGqj
 */

package {
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.events.Event;
    import flash.geom.Rectangle;
    
     [SWF(width=400,height=500,backgroundColor=0xFFFFFF,frameRate=60)]
    public class FlashTest extends Sprite {
        var myArray:Array = new Array();
        
        public function FlashTest() {
        
//ボタンの作成
for (var i:Number = 0; i<7; i++) {
    var myBtn:Sprite = new Sprite();
    with (myBtn.graphics) {
        beginFill(0xCCCCCC,1);
        drawRect(0,0,20,10);
    }
    myBtn.x=50*i+45;
    myBtn.y=395;
    myArray.push(myBtn);
    addChild(myArray[i]);
}

//画面上部分のライン作成
for (var j:Number = 0; j<7; j++) {
    var myLine1:Sprite = new Sprite();
    with (myLine1.graphics) {
        lineStyle(1,0xCCCCCC,1);
        drawRect(0,0,1,340);
    }
    myLine1.x=50*j+50;
    myLine1.y=0;
    addChild(myLine1);
}

//中間ライン作成
var myLine2:Sprite = new Sprite();
with (myLine2.graphics) {
    lineStyle(1,0xCCCCCC,1);
    drawRect(0,340,stage.stageWidth,0);
}
addChild(myLine2);

//ボタンを囲むライン作成
var myLine3:Sprite = new Sprite();
with (myLine3.graphics) {
    lineStyle(1,0xCCCCCC,1);
    drawRect(28,355,345,137);
}
addChild(myLine3);

//ボタン分のライン作成
for (var k:Number = 0; k<7; k++) {
    var myLine4:Sprite = new Sprite();
    with (myLine4.graphics) {
        lineStyle(1,0xCCCCCC,1);
        drawRect(0,0,1,83);
    }
    myLine4.x=50*k+50;
    myLine4.y=394.9;
    addChild(myLine4);
}

myArray[0].addEventListener(MouseEvent.MOUSE_DOWN, xDown);
myArray[1].addEventListener(MouseEvent.MOUSE_DOWN, xDown);
myArray[2].addEventListener(MouseEvent.MOUSE_DOWN, xDown);
myArray[3].addEventListener(MouseEvent.MOUSE_DOWN, xDown);
myArray[4].addEventListener(MouseEvent.MOUSE_DOWN, xDown);
myArray[5].addEventListener(MouseEvent.MOUSE_DOWN, xDown);
myArray[6].addEventListener(MouseEvent.MOUSE_DOWN, xDown);

function xDown(e:MouseEvent):void {
    var rec:Rectangle=new Rectangle(e.target.x,395,0,80);
    e.target.startDrag(true,rec);
    e.target.addEventListener(MouseEvent.MOUSE_MOVE, xMove);
    stage.addEventListener(MouseEvent.MOUSE_UP, xUp);
}
function xMove(e:MouseEvent):void {
    e.updateAfterEvent();
}
function xUp(e:MouseEvent):void {
    e.target.stopDrag();
    e.target.removeEventListener(MouseEvent.MOUSE_MOVE, xMove);
    stage.removeEventListener(MouseEvent.MOUSE_UP, xUp);
}

var myCircle:Sprite = new Sprite();
with (myCircle.graphics) {
    beginFill(0xCCCCCC,1);
    drawCircle(0,0,10);
}
myCircle.x=0;
myCircle.y=30;
addChild(myCircle);

myCircle.addEventListener(Event.ENTER_FRAME, myCircleMove);
function myCircleMove(e:Event):void {
    if (myCircle.x<stage.stageWidth) {
        myCircle.x+=2;
    } else {
        myCircle.x=0;
    }

    //上下位置変更  変なコードでごめんなさい。いつかもっと綺麗に書きたいです。
if ((myCircle.x > myArray[0].x) && (myCircle.x < myArray[1].x)) {
  var PosY1:Number = 30 + (myArray[0].y - 394) * 3;
  if (myCircle.y<PosY1) myCircle.y += (PosY1 -myCircle.y) /3;
  if (myCircle.y>PosY1) myCircle.y -= (myCircle.y - PosY1)/ 3;
 }
 if ((myCircle.x > myArray[1].x) && (myCircle.x < myArray[2].x)) {
  var PosY2:Number = 30 + (myArray[1].y - 394) * 3;
  if (myCircle.y<PosY2) myCircle.y += (PosY2 -myCircle.y) /3;
  if (myCircle.y>PosY2) myCircle.y -= (myCircle.y - PosY2)/ 3;
 }
 if ((myCircle.x > myArray[2].x) && (myCircle.x < myArray[3].x)) {
  var PosY3:Number = 30 + (myArray[2].y - 394) * 3;
  if (myCircle.y<PosY3) myCircle.y += (PosY3 -myCircle.y) /3;
  if (myCircle.y>PosY3) myCircle.y -= (myCircle.y - PosY3)/ 3;
 }
 if ((myCircle.x > myArray[3].x) && (myCircle.x < myArray[4].x)) {
  var PosY4:Number = 30 + (myArray[3].y - 394) * 3;
  if (myCircle.y<PosY4) myCircle.y += (PosY4 -myCircle.y) /3;
  if (myCircle.y>PosY4) myCircle.y -= (myCircle.y - PosY4)/ 3;
 }
 if ((myCircle.x > myArray[4].x) && (myCircle.x < myArray[5].x)) {
  var PosY5:Number = 30 + (myArray[4].y - 394) * 3;
  if (myCircle.y<PosY5) myCircle.y += (PosY5 -myCircle.y) /3;
  if (myCircle.y>PosY5) myCircle.y -= (myCircle.y - PosY5)/ 3;
 }
 if ((myCircle.x > myArray[5].x) && (myCircle.x < myArray[6].x)) {
  var PosY6:Number = 30 + (myArray[5].y - 394) * 3;
  if (myCircle.y<PosY6) myCircle.y += (PosY6 -myCircle.y) /3;
  if (myCircle.y>PosY6) myCircle.y -= (myCircle.y - PosY6)/ 3;
 }
 if ((myCircle.x > myArray[6].x) && (myCircle.x < stage.stageWidth)) {
  var PosY7:Number = 30 + (myArray[6].y - 394) * 3;
  if (myCircle.y<PosY7) myCircle.y += (PosY7 -myCircle.y) /3;
  if (myCircle.y>PosY7) myCircle.y -= (myCircle.y - PosY7)/ 3;
 }
}            // write as3 code here..
            
        }
    }
}