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

What am I doing wrong with this loop?

New Here ,
Jun 21, 2012 Jun 21, 2012

Copy link to clipboard

Copied

This is driving me crazy! I'm trying to create 100 triangles, as a little challenge for myself, in random positions.

import flash.display.MovieClip;

addEventListener(MouseEvent.CLICK, 100Tri)

function 100Tri() {

for(var i:int=0;, i>100;,i++;){

          var positonX:int = Math.random()*550;

          var positonY:int = Math.random()*400;

          var triangle:MovieClip = new Triangles();

          triangle.x=positionX;

          triangle.y=positionY;

 

          addChild(triangle)

 

}

But, it keeps coming up as

Scene 1, Layer 'AS', Frame 1, Line 21084: Syntax error: expecting rightparen before Tri.
Scene 1, Layer 'AS', Frame 1, Line 31084: Syntax error: expecting identifier before 100.

There is a class named 'Triangles', which is linked to a movieclip of a triangle. It contains nothing but what is in every class.

Help? I'm certain its just a little thing I'm missing, but its annoying me. >.<

TOPICS
ActionScript

Views

813

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

Deleted User
Jun 21, 2012 Jun 21, 2012

Hi,

There are some silly mistakes in your code. use the below :

import flash.display.MovieClip;

stage.addEventListener(MouseEvent.CLICK, triangles)

function triangles(e:MouseEvent)

{

          trace("click handler")

          for(var i:int=0; i>100;i++)

          {

                                var positonX:int = Math.random()*550;

                                var positonY:int = Math.random()*400;

                                var triangle:MovieClip = new tri();

                                tria

...

Votes

Translate

Translate
Guest
Jun 21, 2012 Jun 21, 2012

Copy link to clipboard

Copied

Hi,

There are some silly mistakes in your code. use the below :

import flash.display.MovieClip;

stage.addEventListener(MouseEvent.CLICK, triangles)

function triangles(e:MouseEvent)

{

          trace("click handler")

          for(var i:int=0; i>100;i++)

          {

                                var positonX:int = Math.random()*550;

                                var positonY:int = Math.random()*400;

                                var triangle:MovieClip = new tri();

                                triangle.x = positonX;

                                triangle.y = positonY;

          

                                addChild(triangle)

          

          }

}

Regards,

Vipul

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
LEGEND ,
Jun 21, 2012 Jun 21, 2012

Copy link to clipboard

Copied

LATEST

You for loop definition line of code ( for(var i:int=0;, i>100;,i++;){  )should not have any commas in it.

Functions cannot be named starting with numeric characters.

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