Bubble pop game Actionscript: defining ToString() method through a reference with a static type class

Go To StackoverFlow.com


Hello I have the actionscript code here for a bubble popping game. When the game starts, bubbles fall down from the top of the game to the bottom and score is kept for the most bubbles clicked or popped in 30 seconds.

The size of the bubble is defined by the initialize method in the code, and uses ToString() to calculate the score. ToString gives me a 1061: Call to a possibly undefined method Random through a reference with static type uint. This error which I cannot figure out where it comes from.

If anyone with experience in AS3 could give me some pointers to my faults, I would greatly appreciate it. Thank You.

package  {
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.media.Sound;

    public class Ball extends MovieClip{

        static public var burstCounter: uint;
        private var vx: Number;
        private var vy: Number;
        private var gravity: Number;
        private var stageWidth;
        private var stageHeight;
        private var bubble:Ball = new Ball();
        private var score: uint=0;

        public function Ball() {
            bubble.addEventListener(Event.ADDED_TO_STAGE, initialize)
            bubble.addEventListener(MouseEvent.CLICK, burst)
            bubble.addEventListener(Event.ENTER_FRAME, dropping)

        public function initialize (e:Event):void
            bubble.x = Math.random() * stageWidth;
            bubble.y = 0;

            stageWidth = stage.stageWidth;
            stageHeight = stage.stageHeight;

            bubble.vx = Math.random() * 2 - 1;
            bubble.vy = Math.random() * 2 + 1;
            gravity = 0.1;

            var sizeScale = Math.random() * 1.2 + .6;
            bubble.scaleX = bubble.scaleY = sizeScale;
            score = (10 / sizeScale);
            scoreValue.text = score.ToString();

            var colorTran = new ColorTransform();
            colorTran.color = Math.random() * 0xFFFFFF;
            transform.colorTransform = colorTran;
        function dropping(e: Event) :void
            x += vx;
            y += vy;
            vy += gravity;

            if((x<0) || (x>stageWidth) || (y<0) || (y>stageHeight))
                if(parent != null)
                removeEventListener(Event.ENTER_FRAME, dropping)
        function burst (e:Event):void
            var ballonPopping: Sound = new BalloonPopping();
            bubble.removeEventListener(Event.ADDED_TO_STAGE, initialize);
            bubble.removeEventListener(Event.ENTER_FRAME, dropping);


            burstCounter += score;

2012-04-03 22:36
by GivenPie


You need to change each occurrence of




note the lowercase r

Or...since it looks like you just edited this question for ToString()



Notice how similar the errors are. You're tying to call a method that doesn't exist on both of these. Capitalization matters VAR is not the same as var

2012-04-03 22:42
by francis
always prefer toString over ToString, as when you write trace(myObj), toString() is called automatically. You can use this to get useful information about your object rather than it coming out at "[Object object]" or having to call trace(myObj.ToString()) everywher - divillysausages 2012-04-04 21:19


Try Math.random() instead...

2012-04-03 22:42
by Richard Inglis


uint doesn't have a ToString() method either, but it has a toString().

Case is important in method names. :)

2012-04-03 22:56
by Wesley Petrowski


Be mindful that casing does matter when naming & calling properties or methods.

ActionScript uses pascalCasing for its members, including static ones. Constants use ALL_CAPS.

I can't think of any class members in ActionScript that use CamelCasing like you've been doing - as far as I'm aware, there aren't any.

2012-04-03 23:11
by Marty