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

Some balls are flood in to the floor

Community Beginner ,
Aug 18, 2016 Aug 18, 2016

Copy link to clipboard

Copied

  stop();
//ARRAYS
var ballArray:Array = new Array();

//ADD BALLS
var mediumBall1f2:Ball = new Ball  ;
ballArray
.push(mediumBall1f2);
this.addChild(mediumBall1f2);
mediumBall1f2
.ballX = 3;
mediumBall1f2
.ballY = 8;
mediumBall1f2
.x = 300;
mediumBall1f2
.y = 250;
mediumBall1f2
.width = 120;
mediumBall1f2
.height = 120;

var mediumBall1f3:Ball = new Ball  ;
ballArray
.push(mediumBall1f3);
this.addChild(mediumBall1f3);
mediumBall1f3
.ballX = -3;
mediumBall1f3
.ballY = 8;
mediumBall1f3
.x = 200;
mediumBall1f3
.y = 350;
mediumBall1f3
.width = 140;
mediumBall1f3
.height = 140;

var mediumBall1f4:Ball = new Ball  ;
ballArray
.push(mediumBall1f4);
this.addChild(mediumBall1f4);
mediumBall1f4
.ballX = -3;
mediumBall1f4
.ballY = 8;
mediumBall1f4
.x = 300;
mediumBall1f4
.y = 250;
mediumBall1f4
.width = 50;
mediumBall1f4
.height = 50;

var mediumBall1f5:Ball = new Ball  ;
ballArray
.push(mediumBall1f5);
this.addChild(mediumBall1f5);
mediumBall1f5
.ballX = -3;
mediumBall1f5
.ballY = 8;
mediumBall1f5
.x = 400;
mediumBall1f5
.y = 350;
mediumBall1f5
.width = 80;
mediumBall1f5
.height = 80;

var mediumBall1f6:Ball = new Ball  ;
ballArray
.push(mediumBall1f6);
this.addChild(mediumBall1f6);
mediumBall1f6
.ballX = 3;
mediumBall1f6
.ballY = 8;
mediumBall1f6
.x = 400;
mediumBall1f6
.y = 320;
mediumBall1f6
.width = 30;
mediumBall1f6
.height = 30;

var mediumBall1f7:Ball = new Ball  ;
ballArray
.push(mediumBall1f7);
this.addChild(mediumBall1f7);
mediumBall1f7
.ballX = 3;
mediumBall1f7
.ballY = 8;
mediumBall1f7
.x = 400;
mediumBall1f7
.y = 230;

var mediumBall1f8:Ball = new Ball  ;
ballArray
.push(mediumBall1f8);
this.addChild(mediumBall1f8);
mediumBall1f8
.ballX = 3;
mediumBall1f8
.ballY = 8;
mediumBall1f8
.x = 400;
mediumBall1f8
.y = 240;

var mediumBall1f9:Ball = new Ball  ;
ballArray
.push(mediumBall1f9);
this.addChild(mediumBall1f9);
mediumBall1f9
.ballX = 3;
mediumBall1f9
.ballY = 8;
mediumBall1f9
.x = 400;
mediumBall1f9
.y = 110;


//FLOOR
var downArray:Array = new Array();

for (var dA:int = numChildren - 1; dA>= 0; dA--)
{
  
var childdA:DisplayObject = getChildAt(dA);
  
if (childdA.name == "downfloor")
  
{
  downArray
.push(MovieClip(childdA));
  
}
}

var upArray:Array = new Array();

for (var uA:int = numChildren - 1; uA>= 0; uA--)
{
  
var childuA:DisplayObject = getChildAt(uA);
  
if (childuA.name == "upfloor")
  
{
  upArray
.push(MovieClip(childuA));
  
}
}

var rightArray:Array = new Array();

for (var rA:int = numChildren - 1; rA>= 0; rA--)
{
  
var childrA:DisplayObject = getChildAt(rA);
  
if (childrA.name == "rightfloor")
  
{
  rightArray
.push(MovieClip(childrA));
  
}
}

var leftArray:Array = new Array();

for (var lA:int = numChildren - 1; lA>= 0; lA--)
{
  
var childlA:DisplayObject = getChildAt(lA);
  
if (childlA.name == "leftfloor")
  
{
  leftArray
.push(MovieClip(childlA));
  
}
}

//USE ONCE
stageclear
.visible = false;
stageclear
.gotoAndStop(1);

stage
.addEventListener(Event.ENTER_FRAME,ballLoop);
function ballLoop(evt:Event)
{
  
//BALL
  
for (var j = 0; j<ballArray.length; j++)
  
{

  
var ball:Ball = ballArray[j] as Ball;
  ball
.ballY--;
  ball
.y -=  ball.ballY;
  ball
.x -=  ball.ballX;
  
if (player.hitTestObject(ball))
  
{

  ball
.y = 600;
  
}
  
if(ball.x - ball.width/2 < 0)
  
{
  ball
.ballX = -3;
  
}
  
if(ball.x + ball.width/2 > 800)
  
{
  ball
.ballX = 3;
  
}
  
if(ball.y + ball.height/2 > 384.45)
  
{
  ball
.ballY = 20;
  
}
  
if(ball.y - ball.height/2 < 0)
  
{
  ball
.ballY = -2;
  
}
  
for (var d = 0; d<downArray.length; d++)
  
{
  
var down:DownFloor = downArray[d] as DownFloor;
  
if (ball.hitTestObject(down))
  
{
  ball
.ballY = 20;
  
}
  
}
  
for (var r = 0; r<rightArray.length; r++)
  
{
  
var right:RightFloor = rightArray[r] as RightFloor;
  
if (ball.hitTestObject(right))
  
{
  ball
.ballX = 3;
  
}
  
}
  
for (var l = 0; l<leftArray.length; l++)
  
{
  
var left:LeftFloor = leftArray[l] as LeftFloor;
  
if (ball.hitTestObject(left))
  
{
  ball
.ballX = -3;
  
}
  
}
  
for (var u = 0; u<upArray.length; u++)
  
{
  
var up:UpFloor = upArray[u] as UpFloor;
  
if (ball.hitTestObject(up))
  
{
  ball
.ballY = -2;
  
}
  
}
  
if (ball.y >= 600)
  
{
  ball
.parent.removeChild(ball);
  ballArray
.splice(j,1);
  
}
  
if (ballArray.length <= 0)
  
{
  stageclear
.visible = true;
  stageclear
.gotoAndPlay(1);
  
}
  
}
  
if(stageclear.currentFrame == stageclear.totalFrames)
  
{
  stage
.removeEventListener(Event.ENTER_FRAME,ballLoop);
  
MovieClip(this.root).gotoAndPlay(1, "Scene 2");
  
}
}

TOPICS
ActionScript

Views

486

Translate

Translate

Report

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

Community Expert , Aug 18, 2016 Aug 18, 2016

each should have a different name.  eg, downfloor_1, downfloor_2...,upfloor_1,...,leftfloor_1 etc.  you could then use:

var i:int;

for (i = numChildren - 1; i>= 0; i--)
{
  
var childdA:DisplayObject = getChildAt(i);
  
if (childdA.name.indexOf("downfloor")>-1)
  
{
  downArray
.push(MovieClip(childdA));
  
}

if (childdA.name.indexOf("upfloor")>-1)
  
{
  upArray
.push(MovieClip(childdA));
  
}

if (childdA.name.indexOf("leftfloor")>-1)
  
{
  leftArray
.push(MovieClip(childdA));
  
}

if (childdA.name.indexOf("ri

...

Votes

Translate

Translate
Community Expert ,
Aug 18, 2016 Aug 18, 2016

Copy link to clipboard

Copied

do you have a question?

Votes

Translate

Translate

Report

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
Enthusiast ,
Aug 18, 2016 Aug 18, 2016

Copy link to clipboard

Copied

hate when my balls flood to the floor

Votes

Translate

Translate

Report

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
Community Beginner ,
Aug 18, 2016 Aug 18, 2016

Copy link to clipboard

Copied

why some balls are sink in to floors and some others not?

Votes

Translate

Translate

Report

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
Community Expert ,
Aug 18, 2016 Aug 18, 2016

Copy link to clipboard

Copied

the first error i see is it looks like you have more than one object with the same instance name.

Votes

Translate

Translate

Report

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
Community Beginner ,
Aug 18, 2016 Aug 18, 2016

Copy link to clipboard

Copied

this is because i have to many floors and i just want to use less code.

Votes

Translate

Translate

Report

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
Community Expert ,
Aug 18, 2016 Aug 18, 2016

Copy link to clipboard

Copied

each should have a different name.  eg, downfloor_1, downfloor_2...,upfloor_1,...,leftfloor_1 etc.  you could then use:

var i:int;

for (i = numChildren - 1; i>= 0; i--)
{
  
var childdA:DisplayObject = getChildAt(i);
  
if (childdA.name.indexOf("downfloor")>-1)
  
{
  downArray
.push(MovieClip(childdA));
  
}

if (childdA.name.indexOf("upfloor")>-1)
  
{
  upArray
.push(MovieClip(childdA));
  
}

if (childdA.name.indexOf("leftfloor")>-1)
  
{
  leftArray
.push(MovieClip(childdA));
  
}

if (childdA.name.indexOf("rightfloor")>-1)
  
{
  rightArray
.push(MovieClip(childdA));
  
}

}

Votes

Translate

Translate

Report

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
Community Beginner ,
Aug 19, 2016 Aug 19, 2016

Copy link to clipboard

Copied

It works better thank you!!

Votes

Translate

Translate

Report

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
Community Expert ,
Aug 19, 2016 Aug 19, 2016

Copy link to clipboard

Copied

LATEST

you're welcome.

Votes

Translate

Translate

Report

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