34 Replies Latest reply on Jan 19, 2012 5:46 AM by kglad

    Shuffle MovieClips letters _x only;

    andrepazleal Level 1

      The game is already working, only missing a function to random the letters could somebody help me out...?

       

      function make_game()

      {   

          var word_mc = createEmptyMovieClip("word_mc",1);

          var words_array:Array = dica_node.split("<br>");//getting the XML values

          var lines:Number = 0;

          var i:Number = -1;

          var k:Number = 0;

          for (lines; lines < words_array.length; lines++)

          {

              i++;

              word_mc.attachMovie("option_mc", "mc"+i, i);

              word_mc["mc"+i].letter_label.htmlText = words_array[i]

              word_mc["mc"+i]._x = (exercise_description._x)+20;//distance according to the description

              word_mc["mc"+i]._y = (exercise_description._height+exercise_description._y)+45+(65*(lines));

              word_mc_x = word_mc["mc"+i].letter_label._x;

              word_mc_y = word_mc["mc"+i].letter_label._y;

              var letters_array:Array = word_mc["mc"+i].letter_label.text.split("");

              for(var j=0;j<letters_array.length;j++)

              {

                  var letter_mc = word_mc["mc"+i].createEmptyMovieClip("letter_mc"+j,j+300);

                  letter_mc.attachMovie("letter_main", "mc"+j, j);

                  letter_mc["mc"+j].check_mc.check_label.htmlText = letters_array[j];

                  letter_mc["mc"+j]._x = word_mc_x;

                  letter_mc["mc"+j]._y = word_mc_y;

                  var score:Number=0;

                  letter_mc.onPress = function()

                  {

                      this.swapDepths(999);

                      this.startDrag();

                      this._alpha=50;

                  }

                  letter_mc.onRelease = function()

                  {

                      this.stopDrag(true);               

                      if (this.hitTest(this.letter_hit))

                      {

                          score++;

                      }

                      else

                      {

       

                      }

                      if(score == total_mcs)

                      {

                          trace("Finished")

                          ExternalInterface.call("doLMSSetValue",'cmi.core.score.raw',100);

                          ExternalInterface.call("doLMSCommit");

                      }

                  }

                  k++;

                  total_mcs = +k;

                  var letter_hit = letter_mc.letter_hit = word_mc["mc"+i].createEmptyMovieClip("letter_hit"+k,k+100);

                  letter_hit.attachMovie("letter_hit", "mc"+k, k);

                  letter_hit._y = 20

                  letter_hit["mc"+k]._x = word_mc_x;

                  word_mc_x = letter_hit["mc"+k]._x+letter_hit["mc"+k]._width+30

                  letter_hit_x = letter_hit._x;

                  letter_hit_y = letter_hit._y;       

              }       

          }

      }

      }

        • 1. Re: Shuffle MovieClips letters _x only;
          andrepazleal Level 1

          I´ve use an if with the modulo operator like the below, to only change the even values but that is not what I´m looking for, I would like to random the letters between the same word, if I use the below solution the word "FIRST" will became "FRITS", the "R" will swap with "I" and the "S" with the "T" it will give me a pattern on placing the _x values:

           

           

          if(j % 2)

          {   

              letter_mc._x = letter_mc._width/2

          }

           

          Hope you guys understand my frustation...

          • 2. Re: Shuffle MovieClips letters _x only;
            kglad Adobe Community Professional & MVP

            you can use the following to shuffle any array:

             

            function shuffle(a:Array):Array {

                var len:Number = a.length-1;

                for (var ivar:Number = len; ivar>=0; ivar--) {

                    var p:Number = Math.floor(Math.random()*(ivar+1));

                    var t = a[ivar];

                    a[ivar] = a[p];

                    a[p] = t;

                }

                return a;

            }

            1 person found this helpful
            • 3. Re: Shuffle MovieClips letters _x only;
              andrepazleal Level 1

              Thank you for your reply, I have seen the code in other post, but I dont know how to applied on my actual code, could you explain me...?

              • 4. Re: Shuffle MovieClips letters _x only;
                andrepazleal Level 1

                I have two arrays inside the first script, one that grabs the words from the XML and the second array that break the words into letters thru split, should I create another array to store the MovieClips, or store the MovieClips._x...?

                • 5. Re: Shuffle MovieClips letters _x only;
                  andrepazleal Level 1

                  Ok I´m getting there, following my code I have created another array to test outside the for loop, like

                   

                  var my_array:Array = new Array;

                   

                  and inside the loop I use

                   

                  my_array.push(letter_mc["mc"+j]._x);

                   

                  and again outside the loop I use

                   

                  my_array.sort(shuffle);

                   

                  that will call

                   

                  function shuffle():Number

                  {

                      return Math.round(Math.random()*3)-1;

                  }

                   

                  if I trace it give´s me

                   

                  f,i,r,s,t: 82.05,48.1,14.15,116,149.95

                  s,e,c,o,n,d: 149.95,116,82.05,14.15,183.85,48.1

                  t,h,i,r,d: 48.1,149.95,116,82.05,14.15

                   

                  But I realy dont know how to apply into the letters _x position, I think that´s quite simple if you could give me a help...

                  • 6. Re: Shuffle MovieClips letters _x only;
                    andrepazleal Level 1

                    Anyone...? I think, that I´m so close to achieve, can I use those values for to shuffle the position or I´m doing all this and it´s going to end in nothing..?

                    • 7. Re: Shuffle MovieClips letters _x only;
                      kglad Adobe Community Professional & MVP

                      remove your shuffle() function and use the one i suggested.  then if words_array is a collection of words whose letters you want to randomize, use:

                       

                      var score:Number;

                      var dep:Number=0;

                      var gapX:Number;

                      var gapY:Number;

                      var nextX:Number;

                      var nextY:Number;

                      var total_mcs:Number;

                       

                      var word_mc:MovieClip = createEmptyMovieClip("word_mc",dep++);

                       

                      function make_game(){   

                      score=0;

                      gapX=10;

                      gapY=50;

                      nextX=30;

                      nextY=30;

                      removeF();

                       

                      var words_array:Array = dica_node.split("<br>");//getting the XML values

                      total_mcs = 0;

                      for (var lines:Number=0; lines < words_array.length; lines++) {

                      total_mcs+=words_array[lines].length;

                      layoutWordF(words_array[lines].split(""),nextX+350,nextY,false);

                      layoutWordF(shuffle(words_array[lines].split("")),nextX,nextY,true);

                      nextY+= gapY;

                      }

                      }

                       

                      function layoutWordF(wordA:Array,x:Number,y:Number,b:Boolean):Void{

                      var nextX:Number=x;

                      for(var letter:Number=0;letter<wordA.length;letter++){

                              var mc:MovieClip=word_mc.attachMovie("option_mc", "mc_"+dep+letter, dep++);

                              mc.letter_label.htmlText = wordA[letter];

                      mc.letter_label.autoSize="left";

                      mc.letter_label.multiline=false;

                      mc.letter = wordA[letter]; 

                      mc._x = nextX;

                      mc._y = y;

                      mc.origX=mc._x;

                      mc.origY=mc._y;

                      nextX+=mc._width+gapX;

                      if(b){

                      mc.onPress=function(){

                                      this.swapDepths(this._parent.getNextHighestDepth());

                                      this.startDrag();

                                      this._alpha=50;

                      }

                      mc.onRelease = function(){

                                      this.stopDrag(true);               

                                      if (this._droptarget.letter==this.letter) { 

                                          score++;

                                      } else{{

                      this._x=this.origX;

                      this._y=origY;

                                      }

                                      if(score == total_mcs){

                                          trace("Finished")

                                          ExternalInterface.call("doLMSSetValue",'cmi.core.score.raw',100);

                                          ExternalInterface.call("doLMSCommit");

                                      }

                                  }

                      }

                      }

                       

                      function removeF():Void{

                      for(var s:String in word_mc){

                      if(typeof(word_mc[s])=="movieclip"&&word_mc[s]._parent==word_mc){

                      word_mc[s].removeMovieClip();

                      }

                      }

                      }

                      • 8. Re: Shuffle MovieClips letters _x only;
                        andrepazleal Level 1

                        Great I just can´t see what happen to the hitTest MovieClip, im suppose to drop the letter where to check the score...?

                        • 9. Re: Shuffle MovieClips letters _x only;
                          kglad Adobe Community Professional & MVP

                          if the code works correctly (moderate chance because i just wrote it without testing), you'll see a list of scrambled words on the left of the stage and a list of unscrambled letters on the right.  if you drop a left letter on the correct letter on the right, your score increases (and some more code should be added to remove that letter).  otherwise, the dragged letter returns to its start point.

                          • 10. Re: Shuffle MovieClips letters _x only;
                            andrepazleal Level 1

                            Kglad I dont want to bother you, your code its working, for someone that make without testing I think its awesome I just dont know why isnt scoring, first I think that it was a problem with my mc then I remake and placed a label again inside but it still not work...

                            • 11. Re: Shuffle MovieClips letters _x only;
                              kglad Adobe Community Professional & MVP

                              use the trace() function to debug:

                               

                              mc.onRelease = function(){

                                              this.stopDrag(true);      

                              trace(this._droptarget+" "+this._droptarget.letter+" "+this.letter);        

                                              if (this._droptarget.letter==this.letter) { 

                                                  score++;

                                              } else{{

                              this._x=this.origX;

                              this._y=origY;

                                              }

                                              if(score == total_mcs){

                                                  trace("Finished")

                                                  ExternalInterface.call("doLMSSetValue",'cmi.core.score.raw',100);

                                                  ExternalInterface.call("doLMSCommit");

                                              }

                                          }

                              }

                              }

                              1 person found this helpful
                              • 12. Re: Shuffle MovieClips letters _x only;
                                andrepazleal Level 1

                                It returns that the _droptarget.letter is undefined.

                                • 13. Re: Shuffle MovieClips letters _x only;
                                  andrepazleal Level 1

                                  Its only missing two things, the correct values must be points or another movieClip (the user cannot see the right word) and the histTest must work, that conclude 2 weeks of this, for me it was a lot of work, but for you it was easy because you´ve make all again in a couple of minutes, I´ll get there someday...

                                  • 14. Re: Shuffle MovieClips letters _x only;
                                    kglad Adobe Community Professional & MVP

                                    replace:

                                     

                                    trace(this._droptarget+" "+this._droptarget.letter+" "+this.letter);        

                                                    if (this._droptarget.letter==this.letter) { 

                                     

                                    with

                                     

                                          

                                                    if (eval(this._droptarget).letter==this.letter) { 

                                    1 person found this helpful
                                    • 15. Re: Shuffle MovieClips letters _x only;
                                      andrepazleal Level 1

                                      Still keep returning and undefined for the this._droptarget.letter;

                                      • 16. Re: Shuffle MovieClips letters _x only;
                                        kglad Adobe Community Professional & MVP

                                        are you dropping it on one of the other movieclip letters?  ie, your mouse pointer must be over one of the letter movieclips when you drop the dragged letter.  actually, make sure your textfields have a border and a background so you can be sure you're dropping on a letter.

                                        • 17. Re: Shuffle MovieClips letters _x only;
                                          andrepazleal Level 1

                                          Yes I´m dropping above the letter that must be the correct letter but strngely the _droptarget returns and undefined, I don´t know the way you used there, my other script I was using hitTest but this is far more sophistcated..

                                          • 18. Re: Shuffle MovieClips letters _x only;
                                            andrepazleal Level 1

                                            This is my trace, for the FIRST word.

                                             

                                            /word_mc/mc_20/letter_label|undefined|F

                                            /word_mc/mc_31/letter_label|undefined|I

                                            /word_mc/mc_42/letter_label|undefined|R

                                            /word_mc/mc_53/letter_label|undefined|S

                                            /word_mc/mc_64/letter_label|undefined|T

                                            • 19. Re: Shuffle MovieClips letters _x only;
                                              andrepazleal Level 1

                                              I ask in another forum, for example if I had a xml element that have the format values inside, I only like to grab the FIRST, SECOND and THIRD, I´m passing to a TextField so that all format can be lost and then moving to an array, there´s another way...?

                                               

                                              This is the XML:

                                               

                                              <dica><font face='Verdana' size='12' color='#000000'>first<br>second<br>third</font></dica>
                                              Then I´m using:

                                              var words_array:Array = dica_node.split("<br>");

                                              word_mc["mc"+i].letter_label.htmlText = words_array[i]

                                               

                                              • 20. Re: Shuffle MovieClips letters _x only;
                                                kglad Adobe Community Professional & MVP

                                                that's going to be malformed html when you split on <br>.  use the trace() function to see what you're doing:

                                                 

                                                words_array=["<font face='Verdana' size='12' color='#000000'>first","second","third</font"];

                                                 

                                                and use:

                                                 

                                                if (this._droptarget._parent.letter==this.letter) { 
                                                • 21. Re: Shuffle MovieClips letters _x only;
                                                  andrepazleal Level 1

                                                  Hi there Kglad, as to the XML I decide to take out all string between the <> or "&gt;" to "&lt;".

                                                   

                                                  The _droptarget still no good, its not working the same as the others functions return a "undefined" value.

                                                  • 22. Re: Shuffle MovieClips letters _x only;
                                                    andrepazleal Level 1

                                                    Sem título.jpg

                                                    The image above is a sample from my first code the one that I´ve used the modulo operator just to swap the "even" MovieClips, I cant upload zip files here the frum dont allow, that FLA was almost ready only missing the shuffle of the MovieClips, as to your solution, I´ve tried to create and empty square instead of droping on the letters and use hitTest:

                                                     

                                                    var letter_hit:MovieClip = this.createEmptyMovieClip("mc_"+i, 100+i);

                                                            this["mc_"+i].beginFill(0x0070FF,50);

                                                            this["mc_"+i].moveTo(0, 2);

                                                            this["mc_"+i].lineTo(30, 2);

                                                            this["mc_"+i].lineTo(30, 30);

                                                            this["mc_"+i].lineTo(0, 30);

                                                            this["mc_"+i]._x = mc._x

                                                     

                                                    ...if (this.hitTest(letter_hit))

                                                     

                                                    But only work on the last MovieClip, I have created

                                                     

                                                    var letter_hit:MovieClip = createEmptyMovieClip("letter_hit",dep++);

                                                     

                                                    But the way you used to call a function I dont know how it works to apply that...

                                                    • 23. Re: Shuffle MovieClips letters _x only;
                                                      andrepazleal Level 1

                                                      Your code with the hit MovieClip:

                                                       

                                                      var score:Number;

                                                      var dep:Number=0;

                                                      var gapX:Number;

                                                      var gapY:Number;

                                                      var nextX:Number;

                                                      var nextY:Number;

                                                      var total_mcs:Number;

                                                      var word_mc:MovieClip = createEmptyMovieClip("word_mc",dep++);

                                                      var letter_hit:MovieClip = createEmptyMovieClip("letter_hit",dep++);

                                                      function make_game()

                                                      {  

                                                          score=0;

                                                          gapX=10;

                                                          gapY=50;

                                                          nextX=30;

                                                          nextY=30;

                                                          removeF();

                                                          //var words_array:Array = dica_node.split("<br>");//getting the XML values

                                                          var words_array:Array = ['FIRST']

                                                          total_mcs = 0;

                                                          for (var i:Number=0; i < words_array.length; i++)

                                                          {

                                                              total_mcs+=words_array[i].length;

                                                              //layoutWordF(words_array[i].split(""),nextX,nextY+50,false);

                                                              layoutWordF(shuffle(words_array[i].split("")),nextX,nextY,true);

                                                              nextY+= gapY;

                                                          }

                                                      }

                                                      function layoutWordF(wordA:Array,x:Number,y:Number,b:Boolean):Void

                                                      {

                                                          var nextX:Number=x;

                                                          for(var i:Number=0;i<wordA.length;i++)

                                                          {

                                                              var mc:MovieClip=word_mc.attachMovie("option_mc", "mc_"+dep+i, dep++);

                                                              mc.letter_label.htmlText = wordA[i];

                                                              mc.letter_label.autoSize="left";

                                                              mc.letter_label.wordWrap=true;

                                                              mc.letter_label.multiline=false;

                                                              mc.letter = wordA[i];

                                                              mc._x = nextX;

                                                              mc._y = y;

                                                              mc.origX = mc._x;

                                                              mc.origY = mc._y;

                                                              nextX += mc._width+gapX;

                                                              var hit:MovieClip=letter_hit.attachMovie("letter_hit", "hit_"+dep+i, dep++);

                                                              hit.correct= wordA[i];

                                                              hit._x = nextX;

                                                              hit._y = y+40;

                                                              hit.origX = mc._x;

                                                              hit.origY = mc._y;

                                                              //nextX += hit._width+gapX;

                                                              //trace(total_mcs)

                                                              {

                                                                  mc.onPress=function()

                                                                  {

                                                                      this.swapDepths(this._parent.getNextHighestDepth());

                                                                      this.startDrag();

                                                                      this._alpha=50;

                                                                  }

                                                                  mc.onRelease = function()

                                                                  {

                                                                     

                                                                      this.stopDrag(true); 

                                                                      //if (this._droptarget.letter==this.correct)

                                                                      //if (this._droptarget._parent.letter==this.letter)

                                                                      if (this.hitTest(letter_hit))

                                                                      {

                                                                          score++;

                                                                          this._alpha=100;

                                                                          this.enabled=false;

                                                                          trace(score);

                                                                         

                                                                      }

                                                                      else

                                                                      {

                                                                          this._x=this.origX;

                                                                          this._y=this.origY;

                                                                      }

                                                                      if(score == total_mcs)

                                                                      {

                                                                          trace("Finished")

                                                                          ExternalInterface.call("doLMSSetValue",'cmi.core.score.raw',100);

                                                                          ExternalInterface.call("doLMSCommit");

                                                                      }           

                                                                  }

                                                              }

                                                          }

                                                      }

                                                      function removeF():Void

                                                      {

                                                          for(var s:String in word_mc)

                                                          {

                                                              if(typeof(word_mc[s])=="movieclip"&&word_mc[s]._parent==word_mc)

                                                              {

                                                                  word_mc[s].removeMovieClip();

                                                              }

                                                          }

                                                      }

                                                      function shuffle(a:Array):Array

                                                      {

                                                          var len:Number = a.length-1;

                                                          for (var ivar:Number = len; ivar>=0; ivar--)

                                                          {

                                                              var p:Number = Math.floor(Math.random()*(ivar+1));

                                                              var t = a[ivar];

                                                              a[ivar] = a[p];

                                                              a[p] = t;

                                                          }

                                                          return a;

                                                      }

                                                       

                                                      make_game()

                                                      • 24. Re: Shuffle MovieClips letters _x only;
                                                        kglad Adobe Community Professional & MVP

                                                        try:

                                                         

                                                        if (eval(this._droptarget)._parent.letter==this.letter) {

                                                        1 person found this helpful
                                                        • 25. Re: Shuffle MovieClips letters _x only;
                                                          andrepazleal Level 1

                                                          Absolute right...!!! Know I just have to change the letters for another MovieClip than go to the kids...!!!

                                                          • 26. Re: Shuffle MovieClips letters _x only;
                                                            andrepazleal Level 1

                                                            Could you explain how your method work...? For example if I trace(mc), it will return the MovieClips names ok...? But if I want that the mc goes to the center of the right position...?

                                                             

                                                            score++;

                                                            this._alpha=100;

                                                            this.enabled=false;

                                                            trace(score);

                                                            this._x = this.letter._x

                                                            this._y = this.letter._y

                                                            • 27. Re: Shuffle MovieClips letters _x only;
                                                              andrepazleal Level 1

                                                              Shouldnt have a different MovieClip for the right position...?

                                                              • 28. Re: Shuffle MovieClips letters _x only;
                                                                kglad Adobe Community Professional & MVP

                                                                    if (eval(this._droptarget)._parent.letter==this.letter) { 

                                                                                    score++;

                                                                this.removeMovieClip();  // remove the dropped movieclip

                                                                this._x=eval(this._droptarget)._parent._x;  // or position the dropped movieclip over the drop target.

                                                                this._y=eval(this._droptarget)._parent._y;

                                                                                } else{{

                                                                • 29. Re: Shuffle MovieClips letters _x only;
                                                                  andrepazleal Level 1

                                                                  Kglad, you help me out a lot, as I say you remake the whole thing, I pass the last two weeks working on this, but you made in a way that I dont know it could be done, the actions are reduced like 60% or more, could you tell me how can I make other projects that I´m gonna work following your "pattern" of development, a site, an pdf, anything.

                                                                   

                                                                  Know as to the script, if I understand the method that you are using, I need to change the right word to a bunch of points so I should make another movieClip and apply the same ._x location to it...? I dont want to change the _droptarget that you already fixed.

                                                                   

                                                                  Thank you again...

                                                                  • 30. Re: Shuffle MovieClips letters _x only;
                                                                    kglad Adobe Community Professional & MVP

                                                                    if you want to keep the same setup with shuffled words on the left and unshuffled words on the right, you can change make_game to the following and just pass an array of the words you want to use:

                                                                     

                                                                    function make_game(words_array:Array)

                                                                    {  

                                                                        score=0;

                                                                        gapX=10;

                                                                        gapY=50;

                                                                        nextX=30;

                                                                        nextY=30;

                                                                        removeF();

                                                                        //var words_array:Array = dica_node.split("<br>");//getting the XML values

                                                                        //var words_array:Array = a;

                                                                        total_mcs = 0;

                                                                        for (var i:Number=0; i < words_array.length; i++)

                                                                        {

                                                                            total_mcs+=words_array[i].length;

                                                                            //layoutWordF(words_array[i].split(""),nextX,nextY+50,false);

                                                                            layoutWordF(shuffle(words_array[i].split("")),nextX,nextY,true);

                                                                            nextY+= gapY;

                                                                        }

                                                                    }

                                                                    • 31. Re: Shuffle MovieClips letters _x only;
                                                                      andrepazleal Level 1

                                                                      This is exaclty what I need instead of the words_array, points.

                                                                      Sem título.jpg

                                                                      Your AS:

                                                                       

                                                                      function make_game(words_array:Array)

                                                                      {  

                                                                          score=0;

                                                                          gapX=10;

                                                                          gapY=75;

                                                                          nextX=30;

                                                                          nextY=30;

                                                                          removeF();

                                                                          resultado_mc._x=642;

                                                                          resultado_mc._y=448;

                                                                          my_sound.loadSound("sons/"+tela_sound, true);

                                                                          my_sound_2.start(0);

                                                                          var my_format:TextFormat = new TextFormat();

                                                                          my_format.font = "Neo Tech Std";

                                                                          my_format.color = 0xFFFFFF;

                                                                          //my_format.size = 12;

                                                                          my_format.bold= true;

                                                                          my_format.align = "center";

                                                                          trace(dica_node)

                                                                       

                                                                          var my_format_2:TextFormat = new TextFormat();

                                                                          my_format_2.font = "Neo Tech Std";

                                                                          my_format_2.color = 0xFFFFFF;

                                                                          //my_format_2.size = 12;

                                                                          my_format_2.align = "justify";

                                                                       

                                                                          var my_tween:Tween = new Tween(dica_mc, "_xscale", Strong.easeIn, 0, 100, .2, true);

                                                                          var my_tween:Tween = new Tween(dica_mc.dica_label, "_alpha", Strong.easeIn, 0, 100, .5, true);

                                                                          var my_tween:Tween = new Tween(exercicio_panel_mc, "_alpha", Strong.easeIn, 0, 100, .5, true);

                                                                          var my_tween:Tween = new Tween(exercicio_panel_mc, "_yscale", Strong.easeIn, 110, 100, .5, true);

                                                                          var my_tween:Tween = new Tween(exercicio_panel_mc, "_xscale", Strong.easeIn, 110, 100, .5, true);

                                                                          exercicio_panel_mc.exercicio_titulo.htmlText = "<b>Atividades Complementares";

                                                                          exercise_description.htmlText = painel_node;

                                                                          exercise_description.autoSize=true;

                                                                          exercise_description.setTextFormat(my_format_2);

                                                                          //var words_array:Array = dica_node.split("<br>");//getting the XML values

                                                                          var words_array:Array = ['FIRST','SECOND', 'THIRD']

                                                                          //var words_array:Array = dica_node;

                                                                          total_mcs = 0;

                                                                          for (var i:Number=0; i < words_array.length; i++)

                                                                          {

                                                                              total_mcs+=words_array[i].length;

                                                                              //layoutWordF(words_array[i].split(""),nextX+exercise_description._x,nextY+exercise_descr iption._y+exercise_description._height*2,false);

                                                                              layoutWordF(shuffle(words_array[i].split("")),nextX+exercise_description._x,nextY+exercis e_description._y+exercise_description._height,true);

                                                                              nextY+= gapY;

                                                                          }

                                                                         

                                                                      }

                                                                      function layoutWordF(wordA:Array,x:Number,y:Number,b:Boolean):Void

                                                                      {

                                                                          var nextX:Number=x;

                                                                          for(var i:Number=0;i<wordA.length;i++)

                                                                          {

                                                                              var mc:MovieClip=word_mc.attachMovie("option_mc", "mc_"+dep+i, dep++);

                                                                             

                                                                              mc.letter_label.htmlText = '<b>'+wordA[i];

                                                                             

                                                                              mc.letter_label.autoSize="left";

                                                                              mc.letter_label.wordWrap=true;

                                                                              mc.letter_label.multiline=false;

                                                                             

                                                                              mc.letter = wordA[i];

                                                                              mc._x = nextX;

                                                                              mc._y = y;

                                                                              mc.origX = mc._x;

                                                                              mc.origY = mc._y;

                                                                             

                                                                              var hit:MovieClip=letter_hit.attachMovie("letter_hit", "hit_"+dep+i, dep++);

                                                                              hit.correct= wordA[i];

                                                                              hit._x = nextX;

                                                                              hit._y = y+40;

                                                                              hit.origX = mc._x;

                                                                              hit.origY = mc._y;

                                                                              nextX += mc._width+gapX;

                                                                              eval(this._droptarget)._parent._x = 20

                                                                              if(b)

                                                                              {

                                                                                  mc.onPress=function()

                                                                                  {

                                                                                      this.swapDepths(this._parent.getNextHighestDepth());

                                                                                      this.startDrag();

                                                                                      this._alpha=50;

                                                                                  }

                                                                                  mc.onRelease = function()

                                                                                  {

                                                                                      this.stopDrag(true); 

                                                                                     

                                                                                      if (eval(this._droptarget)._parent.letter==this.letter)

                                                                                      {

                                                                                          score++;

                                                                                          //this.removeMovieClip();  // remove the dropped movieclip

                                                                                          //this._x=eval(this._droptarget)._parent._x;  // or position the dropped movieclip over the drop target.

                                                                                          //this._y=eval(this._droptarget)._parent._y;

                                                                                          this.enabled=false;

                                                                                          var my_tween:Tween = new Tween(this, "_x", Bounce.easeIn, this._x, eval(this._droptarget)._parent._x, .4, true);

                                                                                          var my_tween:Tween = new Tween(this, "_y", Bounce.easeIn, this._y, eval(this._droptarget)._parent._y, .4, true);

                                                                                      }

                                                                                      else

                                                                                      {

                                                                                          var my_tween:Tween = new Tween(this, "_x", Bounce.easeIn, this._x, this.origX, .4, true);

                                                                                          var my_tween:Tween = new Tween(this, "_y", Bounce.easeIn, this._y, this.origY, .4, true);

                                                                                      }

                                                                                      if(score == total_mcs)

                                                                                      {

                                                                                          trace("Finished")

                                                                                          ExternalInterface.call("doLMSSetValue",'cmi.core.score.raw',100);

                                                                                          ExternalInterface.call("doLMSCommit");

                                                                                          var my_tween:Tween = new Tween(this, "_alpha", Bounce.easeIn, 0, 20, .4, true);                   

                                                                                      }           

                                                                                  }

                                                                              }

                                                                          }

                                                                      }

                                                                      • 32. Re: Shuffle MovieClips letters _x only;
                                                                        kglad Adobe Community Professional & MVP

                                                                        use:

                                                                         

                                                                         

                                                                        var score:Number;

                                                                        var dep:Number=0;

                                                                        var gapX:Number;

                                                                        var gapY:Number;

                                                                        var nextX:Number;

                                                                        var nextY:Number;

                                                                        var total_mcs:Number;

                                                                         

                                                                        var word_mc:MovieClip = createEmptyMovieClip("word_mc",dep++);

                                                                         

                                                                        function make_game(words_array:Array){   

                                                                        score=0;

                                                                        gapX=10;

                                                                        gapY=50;

                                                                        nextX=30;

                                                                        nextY=30;

                                                                        removeF();

                                                                         

                                                                        total_mcs = 0;

                                                                        for (var lines:Number=0; lines < words_array.length; lines++) {

                                                                        total_mcs+=words_array[lines].length;

                                                                        layoutWordF(words_array[lines].split(""),nextX,nextY+gapY,false);

                                                                        layoutWordF(shuffle(words_array[lines].split("")),nextX,nextY,true);

                                                                        nextY+= gapY*2;

                                                                        }

                                                                        }

                                                                         

                                                                        function layoutWordF(wordA:Array,x:Number,y:Number,b:Boolean):Void{

                                                                        var nextX:Number=x;

                                                                        for(var letter:Number=0;letter<wordA.length;letter++){

                                                                        if(b){

                                                                                var mc:MovieClip=word_mc.attachMovie("option_mc", "mc_"+dep+letter, dep++);

                                                                                mc.letter_label.htmlText = wordA[letter];

                                                                        mc.letter_label.autoSize="left";

                                                                        mc.letter_label.multiline=false;

                                                                        } else {

                                                                        var mc:MovieClip=word_mc.attachMovie("dotID", "mc_"+dep+letter, dep++);  // create a movieClip with linkage id="dotID"

                                                                        }

                                                                        mc.letter = wordA[letter]; 

                                                                        mc._x = nextX;

                                                                        mc._y = y;

                                                                        mc.origX=mc._x;

                                                                        mc.origY=mc._y;

                                                                        nextX+=mc._width+gapX;

                                                                        if(b){

                                                                        mc.onPress=function(){

                                                                                        this.swapDepths(this._parent.getNextHighestDepth());

                                                                                        this.startDrag();

                                                                                        this._alpha=50;

                                                                        }

                                                                        mc.onRelease = function(){

                                                                                        this.stopDrag(true);               

                                                                         

                                                                                        if (eval(this._droptarget).letter==this.letter)

                                                                                            score++;

                                                                          this.enabled=false;

                                                                                            var my_tween:Tween = new Tween(this, "_x", Bounce.easeIn, this._x, eval(this._droptarget)._parent._x, .4, true);

                                                                                            var my_tween:Tween = new Tween(this, "_y", Bounce.easeIn, this._y, eval(this._droptarget)._parent._y, .4, true);

                                                                                        } else{{

                                                                        this._x=this.origX;

                                                                        this._y=origY;

                                                                                        }

                                                                                        if(score == total_mcs){

                                                                                            trace("Finished")

                                                                                            ExternalInterface.call("doLMSSetValue",'cmi.core.score.raw',100);

                                                                                            ExternalInterface.call("doLMSCommit");

                                                                                        }

                                                                                    }

                                                                        }

                                                                        }

                                                                         

                                                                        function removeF():Void{

                                                                        for(var s:String in word_mc){

                                                                        if(typeof(word_mc[s])=="movieclip"&&word_mc[s]._parent==word_mc){

                                                                        word_mc[s].removeMovieClip();

                                                                        }

                                                                        }

                                                                        }

                                                                        • 33. Re: Shuffle MovieClips letters _x only;
                                                                          andrepazleal Level 1

                                                                          Kglad thank you for your kind help I´ve learn a lot from all this. I only have a small glitch as to the XML parse that I quote before.

                                                                           

                                                                          Im getting the nodeValue from an external software, I cannot change anything in this XML have to used like it is so I´m getting the value and applying into the "dica_node"

                                                                           

                                                                          dica_node = root_node.childNodes[i].childNodes[4].firstChild.nodeValue;

                                                                           

                                                                          Until there, everything is ok, my problem is:

                                                                           

                                                                          temp_mc.htmlText = dica_node.split("<br>")

                                                                           

                                                                          I have to apply (that was the only way I found for this) the content inside an textField called "temp_mc" so I the node can loose all formating information, that unfortunattely is it inside the nodeValue:

                                                                           

                                                                          <dica><font face='Verdana' size='12' color='#000000'>first<br>second<br>third</font></dica>

                                                                           

                                                                          So after I just placed inside the array:

                                                                           

                                                                          var words_array:Array = temp_mc.text.split(',')

                                                                           

                                                                          Theres another way I can do that, without using textField on stage and etc...? Knowing that the "<font face='Verdana' size='12' color='#000000'>" can change to anything, it will all deppend on how the XML come to me.

                                                                           

                                                                          Thank yu so much...

                                                                          • 34. Re: Shuffle MovieClips letters _x only;
                                                                            kglad Adobe Community Professional & MVP

                                                                            start a new thread for this.