8 Replies Latest reply on Mar 6, 2012 8:34 AM by fonzio1

    maths style jigsaw?

    fonzio1

      hi all

       

      i havent used as2 for around 3 years now, been getting stuck in as3 and as a result ive kind of forgotten as2,

       

      I need to write a maths game for a friend, basically i have movieclips (1 to 10_mc) featuring graphical representations of numbers and i need to randomise how they are shown

       

      so basically 10_mc - 2_mc, so i think i will basically need to put them into string format

       

      I also need the - or + to be random and the answer to never equal less than zero

       

      you see im wishing to setup a jigsaw where the player can drag numbers into the answerbox (like a jigsaw)

       

      I plan to have the shape of the number being dragged available in the answer movieclip, so that if they match the result will be correct

       

      wondering how to go about this ?

       

      does anyone have any tutorials on this kind of thing?

       

      thanks

      fonzio

        • 1. Re: maths style jigsaw?
          kglad Adobe Community Professional & MVP

          didn't we just go through this?

           

          anyway, you can't start an object name with a number so start by naming your movieclips mc_1, mc_2 etc.

          1 person found this helpful
          • 2. Re: maths style jigsaw?
            fonzio1 Level 1

            oh hi kglad, yes we went through something similar for as3,

             

            wondering how it can be done in as2 as its quite different and my mind is all addeventlistener now

             

            was just thinking aloud at that point, but ive started a test app and named the mcs to mc_1 etc as you suggested

             

            i do have code for a jigsaw but its as3 and i dont think it will work with as2

             

            thanks

            fonzio

            • 3. Re: maths style jigsaw?
              kglad Adobe Community Professional & MVP

              unless you're much better at as2 coding than as3, you should be using as3.

               

              but if you must use as2, did you add as2 drag-and-drop code, yet?

              • 4. Re: maths style jigsaw?
                fonzio1 Level 1

                hi

                 

                no the problem is im unsure of how to go about it using as2, should i use hittarget, or something else?, i do need to use as2 to accomplish this

                i have this code (monkeyflash) which works well in as3, however wondering if it can somehow be ported to as2?

                 

                var startX:Number;
                var startY:Number;
                var counter:Number=0;
                var tries:Number=0;
                var myfintimer:Timer;
                var myfin2timer:Timer;
                var myfin3timer:Timer;

                finished_mc.visible=false;

                jig1_mc.buttonMode=true;
                jig2_mc.buttonMode=true;
                jig3_mc.buttonMode=true;
                jig4_mc.buttonMode=true;
                jig5_mc.buttonMode=true;
                jig6_mc.buttonMode=true;
                jig7_mc.buttonMode=true;
                jig8_mc.buttonMode=true;
                jig9_mc.buttonMode=true;
                jig10_mc.buttonMode=true;


                jig1_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
                jig1_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
                jig2_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
                jig2_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
                jig3_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
                jig3_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
                jig4_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
                jig4_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
                jig5_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
                jig5_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
                jig6_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
                jig6_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
                jig7_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
                jig7_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
                jig8_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
                jig8_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
                jig9_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
                jig9_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
                jig10_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
                jig10_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);


                function pickUp(event:MouseEvent):void {
                event.target.startDrag(true);

                event.target.parent.addChild(event.target);
                event.target.gotoAndStop(2);
                startX=event.target.x;
                startY=event.target.y;
                }
                function dropIt(event:MouseEvent):void {
                event.target.stopDrag();
                var myTargetName:String="target"+event.target.name;
                var myTarget:DisplayObject=getChildByName(myTargetName);
                if (event.target.dropTarget!=null&&event.target.dropTarget.parent==myTarget) {
                  event.target.play();
                  borders_mc.parent.setChildIndex(borders_mc, borders_mc.parent.numChildren-1);
                  MovieClip(parent.parent).scoreplus();
                  MovieClip(parent.parent).e_mc.cap_talk_txt.text = "Good Job!!";
                 
                  event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp);
                  event.target.removeEventListener(MouseEvent.MOUSE_UP, dropIt);
                 
                  event.target.buttonMode=false;
                  event.target.x=myTarget.x;
                  event.target.y=myTarget.y;
                  counter++;

                 

                 

                of course this code uses a copy of the original jigsaw piece as a target with its alpha set to 0

                 

                the problem will eventually turn out to be

                 

                random (- or +) random = answer

                 

                so flash will need to do the sum itself and then put the proper target jigsaw piece into place, so that when the user drags the correct number it will fit and come out as correct, the number can then return to its start x and y

                 

                hope this is understandable

                 

                thanks

                fonzio

                • 5. Re: maths style jigsaw?
                  kglad Adobe Community Professional & MVP

                  yes, that can be re-written using as2 but what's the purpose of making more work for yourself?

                  • 6. Re: maths style jigsaw?
                    fonzio1 Level 1

                    hi kglad, hmm well i finished the as3 project and now im working on trying to covert this jigsaw maths style game into as2, the reason being is that my friend is only familiar with as2 and needs it doing in that language

                     

                    he is currently away however and wants me to work on it until he returns

                     

                    would you kindly help me to port this to as2 please?

                     

                    much appreciated

                    fonzio

                    • 7. Re: maths style jigsaw?
                      kglad Adobe Community Professional & MVP

                      use:

                      var tl:MovieClip=this;

                      var startX:Number;
                      var startY:Number;
                      var counter:Number=0;
                      var tries:Number=0;

                      finished_mc._visible=false;

                       

                      for(var i:Number=1;i<=10;i++){

                      this["jig"+i+"_mc"].onPress=pickUp;

                      this["jig"+i+"_mc"].onRelease=dropIt;

                      }


                      function pickUp():Void {
                      this.startDrag(true);
                      this.swapDepths(this._parent.getNextHighestDepth());
                      this.gotoAndStop(2);
                      startX=this._x;
                      startY=this._y;
                      }
                      function dropIt():Void {
                      this.stopDrag();
                      var myTargetName:String="target"+this._name;
                      var myTarget = tl[myTargetName];
                      if (eval(this._droptarget)._parent==myTarget) {
                        this.play();
                        borders_mc.swapDepths(borders_mc._parent.getNextHighestDepth());
                        tl._parent._parent.scoreplus();
                      tl._parent._parent.e_mc.cap_talk_txt.text = "Good Job!!";
                       
                      delete this.onPress
                      delete this.onRelease

                      this._x=myTarget._x;
                      this._y=myTarget._y;
                        counter++;

                       

                      1 person found this helpful
                      • 8. Re: maths style jigsaw?
                        fonzio1 Level 1

                        hi kglad,

                         

                        finally got around to testing this, had to change some of the code to get it to score a hit on target or a miss

                         

                        by the way the pieces being dragged are called jig1_mc, jig2_mc and so on

                         

                        and the targets are called target_jig1_mc, target_jig2_mc and so on

                         

                        var tl:MovieClip=this;

                        var startX:Number;
                        var startY:Number;

                         

                        for(var i:Number=1;i<=10;i++){

                        this["jig"+i+"_mc"].onPress=pickUp;

                        this["jig"+i+"_mc"].onRelease=dropIt;

                        }


                        function pickUp():Void {
                        this.startDrag(true);
                        this.swapDepths(this._parent.getNextHighestDepth());

                        startX=this._x;
                        startY=this._y;
                        }
                        function dropIt():Void {
                        this.stopDrag();
                        var myTargetName:String="target"+this._name;
                        var myTarget = tl[myTargetName];
                        if (eval(this._droptarget)._parent!=myTarget) {
                        trace("hit!")
                        myTarget.gotoAndStop(2);

                         


                        /*delete this.onPress
                        delete this.onRelease*/

                        /*this._x=myTarget._x;
                        this._y=myTarget._y;*/

                         

                        }
                        else
                        trace("miss");
                        myTarget.gotoAndStop(1);
                        this._x=startX;
                        this._y=startY;
                        }

                         

                        basically had to comment out delete this.onPress and release as it would stop the game,

                        everything works fine however how do i tell the target to play on a hit?

                        i assume tl relates to the stage?, because if i left it as == and i dropped anywhere on stage i would score a hit so had to change it around

                         

                        need the dragged number to return to its place and the target to play before disappearing and then to replace the target with another target (this will be when we add the random number + or - random number = functionality)

                        so flash could add it up and display the target we need to put into place

                         

                        hope you can help

                        appreciated as always

                        fonzio