dcsimg
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: throw object

  1. #1
    Senior Member
    Join Date
    Jan 2007
    Location
    Nottingham, England
    Posts
    263

    throw object

    Hi,

    been working on a throw script for a button (attached the file)

    the throw works sort of - it sticks a little and doesnt bounce very well. can anyone see what's causing it?

    PHP Code:
    package {

        
    import flash.display.*;
        
    import flash.events.*;
        
    import flash.geom.Rectangle;

        public class 
    throwing extends MovieClip {

            private var 
    menu1:linesBlock;
            private var 
    menu2:linesBlock;
            private var 
    bounce:Number = -0.7;
            private var 
    friction:Number 0.9;
            private var 
    vx:Number;
            private var 
    oldX:Number;

            public function 
    throwing() {

                
    init();
            }
            private function 
    init() {

                
    stage.scaleMode StageScaleMode.NO_SCALE;
                
    stage.align StageAlign.TOP_LEFT;

                
    menu1= new linesBlock;
                
    addChild(menu1);
                
    menu1.stage.stageHeight/2;
                
    menu1.addEventListener(MouseEvent.MOUSE_DOWNonMousedown);
                

                
    addEventListener(Event.ENTER_FRAMEonEnterFrame);

            }
            public function 
    onEnterFrame(event:Event):void {

                
    menu1.stage.stageHeight/2;
                
    menu1.+= vx;
                
    vx *= friction;
                var 
    left 0;
                var 
    right stage.stageWidth;
                
                if (
    menu1.right -160){
                    
    vx*= bounce;
                }
                else if (
    menu1.left+10){
                    
    vx*= bounce;
                }

            }
            private function 
    onMousedown(event:MouseEvent):void {

                
    oldX menu1.x;
                
    stage.addEventListener(MouseEvent.MOUSE_UPonMouseup);
                
    menu1.startDrag(false, new Rectangle(0menu1.ymenu1.width0));
                
    removeEventListener(Event.ENTER_FRAMEonEnterFrame);
                
    addEventListener(Event.ENTER_FRAMEtrackVelocity);
            }
            private function 
    onMouseup(event:MouseEvent):void {

                
    stage.removeEventListener(MouseEvent.MOUSE_UPonMouseup);
                
    menu1.stopDrag();
                
    removeEventListener(Event.ENTER_FRAMEtrackVelocity);
                
    addEventListener(Event.ENTER_FRAMEonEnterFrame);

            }
            private function 
    trackVelocity(event:Event):void {

                
    vx menu1.oldX;
                
    oldX menu1.x;

            }
        }

    Attached Files Attached Files

  2. #2
    Senior Member
    Join Date
    Jan 2007
    Location
    Nottingham, England
    Posts
    263
    figured out the jumping - changed the parameters for the rectangle in the startDrag script to :

    menu1.startDrag(false, new Rectangle (0, menu1.y, stage.stageWidth, 0));

    cant figure out the reason the bouncing doesnt always work when it hits the right stage edge though?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center