2 Replies Latest reply: Jun 21, 2012 8:48 AM by Ned Murphy RSS

    What am I doing wrong with this loop?

    snuffsTheThundarKat

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

        • 1. Re: What am I doing wrong with this loop?
          vipul.khandelwal Community Member

          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

          • 2. Re: What am I doing wrong with this loop?
            Ned Murphy CommunityMVP

            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.