Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Attempted access of inaccessible property radius through a reference with static type Ball.

New Here ,
May 29, 2013 May 29, 2013

hai guys...
i dont know why my coding cannot run..
this is the problem that i have to face it..

package

{

import flash.display.Sprite;

import flash.events.Event;

public class Bubbles extends Sprite

{

private var balls:Array;

private var numBalls:Number = 30;

private var bounce:Number = -0.5;

private var spring:Number = 0.05;

private var gravity:Number = 0.1;

public function Bubbles()

{

init();

}

private function init():void

{

balls = new Array();

for(var i:uint = 0; i < numBalls; i++)

{

var ball:Ball = new Ball(Math.random() * 30 + 20,

Math.random() * 0xffffff);

ball.x = Math.random() * stage.stageWidth;

ball.y = Math.random() * stage.stageHeight;

//ball.vx = Math.random() * 6 - 3;

//ball.vy = Math.random() * 6 - 3;

addChild(ball);

balls.push(ball);

}

addEventListener(Event.ENTER_FRAME, onEnterFrame);

}

private function onEnterFrame(event:Event):void

{

for(var i:uint = 0; i < numBalls - 1; i++)

{

var ball0:Ball = balls;

for(var j:uint = i + 1; j < numBalls; j++)

{

var ball1:Ball = balls;

var dx:Number = ball1.x - ball0.x;

var dy:Number = ball1.y - ball0.y;

var dist:Number = Math.sqrt(dx * dx + dy * dy);

var minDist:Number = ball0.radius + ball1.radius;

if(dist < minDist)

{

var angle:Number = Math.atan2(dy, dx);

var tx:Number = ball0.x + Math.cos(angle) *

minDist;

var ty:Number = ball0.y +

Math.sin(angle) *

minDist;

var ax:Number = (tx - ball1.x) *

spring;

var ay:Number = (ty - ball1.y) *

spring;

ball0.vx -= ax;

ball0.vy -= ay;

ball1.vx += ax;

ball1.vy += ay;

}

}

}

for(i = 0; i < numBalls; i++)

{

var ball:Ball = balls;

move(ball);

}

}

private function move(ball:Ball):void

{

ball.vy += gravity;

ball.x += ball.vx;

ball.y += ball.vy;

if(ball.x + ball.radius > stage.stageWidth)

{

ball.x = stage.stageWidth - ball.radius;

ball.vx *= bounce;

}

else if(ball.x - ball.radius < 0)

{

ball.x = ball.radius;

ball.vx *= bounce;

}

if(ball.y + ball.radius > stage.stageHeight)

{

ball.y = stage.stageHeight - ball.radius;

ball.vy *= bounce;

}

else if(ball.y - ball.radius < 0)

{

ball.y = ball.radius;

ball.vy *= bounce;

}

}

}

}

TOPICS
ActionScript
711
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 29, 2013 May 29, 2013

The error is telling you that your Ball class does not have a radius property.  Chances are you need to create such a property in that class.

Translate
LEGEND ,
May 29, 2013 May 29, 2013

The error is telling you that your Ball class does not have a radius property.  Chances are you need to create such a property in that class.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 29, 2013 May 29, 2013
LATEST

What is the Ball class. Is it a symbol in the library of the FLA or is it just an AS class file. I think the ball class Ball has an AS file seeing as it takes agruments. If so where is the AS class file located. Is Ball.as in the same folder as Bubbles.as

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines