Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 03-25-2010, 01:27 AM   #1
amylou_184
Registered User
 
Join Date: Mar 2010
Posts: 2
Default [AS3] Pinball game error

Hi I'm trying to make a pinball game and there is an error that keeps appearing. Below is the code I am using:
ActionScript Code:
// package {     import flash.display.*;     import flash.geom.*;     import flash.events.*;     import flash.ui.*;         public class BouncingObject extends Sprite     {         private var Mxpos:Number;         private var Mypos:Number;         private var Mxvel:Number;         private var Myvel:Number;         private var Mgrav:Number;         private var Mdirection_D:Number;         private var Mdirection_R:Number;                                 public function BouncingObject(Pxpos:Number, Pypos:Number, Pxvel:Number, Pyvel:Number, Pgrav:Number)         {             //store parameters             Mxpos = Pxpos;             Mypos = Pypos;             Mxvel = Pxvel;             Myvel = Pyvel;             Mgrav = Pgrav;                              var Ball:Sprite = new Ball1();             addChild(Ball);                         //set current position             x = Mxpos;             y = Mypos;                         //other things to load once the stage is up and running             addEventListener(Event.ADDED_TO_STAGE, loadComplete, false, 0, true);         }                 public function loadComplete(evt:Event):void         {             var Hippo1:Sprite = new HippoObject1();             parent.addChild(Hippo1);             //Place in the middle             Hippo1.x=275;             Hippo1.y=400;                         //Add frame listener             addEventListener(Event.ENTER_FRAME, onRun, false, 0, true);             stage.addEventListener(KeyboardEvent.KEY_DOWN, BallLauncher);         }                 public function BallLauncher (event:KeyboardEvent):void         {             if (event.keyCode == Keyboard.DOWN)             {             Myvel= -50;             }         }                    //Deal with a collision with a horizontal surface         private function doCollisionH():void         {             //Get current angle             Mdirection_R = Math.atan2 (Mypos-y, Mxpos -x);                         //Convert to degrees             Mdirection_D = Mdirection_R * (180/Math.PI);                                 //Check angle is a +ve number             if (Mdirection_D < 0)             {             Mdirection_D += 360;             }                         //Get new angle             Mdirection_D = (180-Mdirection_D)+180;             //Check angle is a +ve number             if (Mdirection_D < 0)             {             Mdirection_D += 360;             }             //Get speed along angle             var speed:Number = Math.sqrt ((Mxvel*Mxvel)+(Myvel*Myvel));             //Apply friction?             speed*= 0.9;             //Convert degrees to radians             Mdirection_R = (Math.PI/180) * Mdirection_D;             //Set Mxvel and Myvel speed             Mxvel = speed*Math.cos (Mdirection_R);             Myvel = speed*Math.sin (Mdirection_R);         }                 //Deal with a collision with a vertical surface         private function doCollisionV():void         {             //Get current angle             Mdirection_R = Math.atan2 (Mypos-y, Mxpos -x);                         //Convert to degrees             Mdirection_D = Mdirection_R * (180/Math.PI);                         //Check angle is a +ve number             if (Mdirection_D < 0)             {             Mdirection_D += 360;             }                         //Get new angle             Mdirection_D =(180-Mdirection_D);             //Check angle is a +ve number             if (Mdirection_D < 0)             {             Mdirection_D += 360;             }             //Get speed along angle             var speed:Number = Math.sqrt ((Mxvel*Mxvel)+(Myvel*Myvel));             //Apply friction?             speed*= 0.9;             //Convert degrees to radians             Mdirection_R = (Math.PI/180) * Mdirection_D;             //Set Mxvel and Myvel speed             Mxvel = speed*Math.cos (Mdirection_R);             Myvel = speed*Math.sin (Mdirection_R);         }                 private function onRun(evt:Event):void         {             //Increase Y velocity by gravity             Myvel += Mgrav;             //Increase X position by X velocity             Mxpos += Mxvel;             //Increase Y position by Y velocity             Mypos += Myvel;                     //Check for collision with stage             //Hitting Bottom             if (Mypos+height > stage.stageHeight)             {                 //React to collision                 doCollisionH();                                                 //Change ball position                 Mypos = stage.stageHeight - height;                 y = Mypos;                             }                         //Hitting Top             else if (Mypos < 0)             {                 //React to collision                 doCollisionH();                                                 //Change ball position                 Mypos = 0;                 y = Mypos;                             }                         //Hitting Right             else if (Mxpos+width > stage.stageWidth)             {                 //React to collision                 doCollisionV();                                     //Change ball position                 Mxpos = stage.stageWidth - width;                 x = Mxpos;                             }                         //Hitting Left             else if (Mxpos < 0)             {                 //React to collision                 doCollisionV();                                 //Change ball position                 Mxpos = 0;                 x = Mxpos;                             }             if (y+height<HippoObject1.y||y>HippoObject1.y+HippoObject1.height)              {                  var topDistanceb:int= Math.abs(HippoObject1.y - (y+height));                  var bottomDistanceb:int=Math.abs(HippoObject1.y+HippoObject1.height-y);                if (topDistanceb<bottomDistanceb) {               doCollisionH();               Mypos=HippoObject1.y-height;               y=Mypos;              }             else {               doCollisionH();               Mypos=HippoObject1.y+HippoObject1.height;               y=Mypos;       }       }             else if (x+width<HippoObject1.x||x>HippoObject1.x+HippoObject1.width) {             var leftDistanceb:int= Math.abs(HippoObject1.x - (x+width));             var rightDistanceb:int=Math.abs(HippoObject1.x+HippoObject1.width-x);              if (leftDistanceb<rightDistanceb)              {               doCollisionV();               Mxpos=HippoObject1.x-width;               x=Mxpos;              }              else              {               doCollisionV();               Mxpos=HippoObject1.x+HippoObject1.width;               x=Mxpos;               }            }           if (Mdirection_D<0)            {            Mdirection_D+=360;         }             //Update position of ball (only done here when there are no collisions)                 x = Mxpos;                 y = Mypos;         }                         //Collision with box                             //Hitting top                                             //React to collision                                             //Change ball position                                                             //Hitting bottom                                             //React to collision                                             //Change ball position                                         //Hitting left                                             //React to collision                                             //Change ball position                                         //hitting right                                             //React to collision                                             //Change ball position                         } }
The error I am getting is :
1119: Access of possibly undefined property y through a reference with static type Class.

Thanks in advance.

Last edited by CyanBlue; 03-25-2010 at 01:45 AM. Reason: AS Tag applied...
amylou_184 is offline   Reply With Quote
Old 03-25-2010, 01:48 AM   #2
UncleNinja
I love noogies.
 
UncleNinja's Avatar
 
Join Date: Mar 2009
Location: Georgia, USA
Posts: 786
Default

What line is that thrown on?
(Use debug to see - Control-Shift-Enter)
__________________
-UncleNinja on Twitter

ActionScript Hints - a revolutionary wiki dedicated to helping Flash developers
UncleNinja is offline   Reply With Quote
Old 03-25-2010, 01:52 AM   #3
amylou_184
Registered User
 
Join Date: Mar 2010
Posts: 2
Default

The problems appear in here:
if (y+height<HippoObject1.y||y>HippoObject1.y+HippoOb ject1.height)
{
var topDistanceb:int= Math.abs(HippoObject1.y - (y+height));
var bottomDistanceb:int=Math.abs(HippoObject1.y+HippoO bject1.height-y);

if (topDistanceb<bottomDistanceb) {
doCollisionH();
Mypos=HippoObject1.y-height;
y=Mypos;
}
else {
doCollisionH();
Mypos=HippoObject1.y+HippoObject1.height;
y=Mypos;
}

}
else if (x+width<HippoObject1.x||x>HippoObject1.x+HippoObj ect1.width) {
var leftDistanceb:int= Math.abs(HippoObject1.x - (x+width));
var rightDistanceb:int=Math.abs(HippoObject1.x+HippoOb ject1.width-x);

if (leftDistanceb<rightDistanceb)
{
doCollisionV();
Mxpos=HippoObject1.x-width;
x=Mxpos;
}
else
{
doCollisionV();
Mxpos=HippoObject1.x+HippoObject1.width;
amylou_184 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:23 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.