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

Gravity in as2

New Here ,
Jun 17, 2014 Jun 17, 2014

Hey I'm new at AS, and i have been trying to make an object (a ball) fall within gravity but nothing happens when i'm running the swf.

here's the code:

onClipEvent (load) {

    fallMax = 0;

}

onClipEvent (enterFrame) {

    if (ball._y < 300)

    {

        _y += fallMax;

        if (fallMax < 10)

        {

            fallmax++;

        }

    }

}

what am i doing wrong?

TOPICS
ActionScript
407
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

Community Expert , Jun 17, 2014 Jun 17, 2014

you probably have some scope problems.  but rather than correct those, you should remove all code from objects and attach code to timelines:

var fallMax:Number=0;

this.onEnterFrame=gameloopF;

function gameloopF():Void{

if(ball._y<300){

ball._y+=fallMax

if(fallMax<10){

fallMax++;

}

} else {

delete this.onEnterFrame;

}

}

Translate
Community Expert ,
Jun 17, 2014 Jun 17, 2014

you probably have some scope problems.  but rather than correct those, you should remove all code from objects and attach code to timelines:

var fallMax:Number=0;

this.onEnterFrame=gameloopF;

function gameloopF():Void{

if(ball._y<300){

ball._y+=fallMax

if(fallMax<10){

fallMax++;

}

} else {

delete this.onEnterFrame;

}

}

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
New Here ,
Jun 18, 2014 Jun 18, 2014

Thank you

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
Community Expert ,
Jun 18, 2014 Jun 18, 2014
LATEST

you're welcome.

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