Skip navigation
snuffsTheThundarKat
Currently Being Moderated

What am I doing wrong with this loop?

Jun 21, 2012 6:18 AM

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. >.<

 
Replies
  • Currently Being Moderated
    Jun 21, 2012 7:01 AM   in reply to snuffsTheThundarKat

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 21, 2012 8:48 AM   in reply to snuffsTheThundarKat

    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.

     

    
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points