22 Replies Latest reply on Nov 16, 2006 2:00 PM by Ricky2k7

    Puzzel Game

    Ricky2k7 Level 1
      Hi
      I've created a simple puzzel game in flash, where the user has to drag several objects to a specific areas on a board, no problem here.
      But there's 2 things i can't do. First i want to jump to another layer when all the objects are in there places, i tryed to do that with a if() but didn't work :-S Second i want to know if its possible to random the objects, so that every time someone plays the game the objects are in a diferent order.

      Here's my puzzel source: http:\\www.rld-i.com\puzzel.fla

      Can anyone help me?
        • 1. Re: Puzzel Game
          Level 7
          IndioDoido,

          > I've created a simple puzzel game in flash, where the user has
          > to drag several objects to a specific areas on a board, no
          > problem here.

          Okay.

          > But there's 2 things i can't do. First i want to jump to another
          > layer when all the objects are in there places, i tryed to do that
          > with a if() but didn't work :-S

          Well, what did you try? :)

          You'd have to know beforehand what the "correct" places are. You could
          then cycle through the pieces (these are movie clips, right?) and use if()
          to check if each piece's current location matched (or was close) to the
          "correct" location. I would run this check every time the user releases one
          of the pieces.

          > Second i want to know if its possible to random the objects, so
          > that every time someone plays the game the objects are in a
          > diferent order.

          You betcha. It's possible. :)

          How are you positioning these pieces in the first place? Are you doing
          so with ActionScript? If so, all you have to do is use the Math.random()
          method to determine a random _x and _y position. Let's see your code.

          > Here's my puzzel source: http:\\www.rld-i.com\puzzel.fla

          I think you're likely to be better served if you post your relevant code
          here in the forum. It'll encourage you to think through what you've done so
          far, and to be able to articulate why you made certain decisions. Besides,
          then others can join in the discussion. :)


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: Puzzel Game
            Ricky2k7 Level 1
            Hi David!

            I gave the .fla so that it could be easier to explain.
            This is the code that I have on every object (mc). This makes the object drag and snap to it's specific area.
            Know...i would like to know how can i "jump" to another layer when all the objects are in their specific areas.
            Since the objects and the areas are in the main stage, i wrote this code in a Actions layer:

            if (_root.object1._x ==_root.area1._x && _root.object1._y == _root.area1._y
            ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
            ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
            _root.object9._x ==_root.area9._x && _root.object9._y == _root.area9._y;)
            {
            gotoAndPlay("nextFrame");
            }

            But it didn't work...
            I'm starting with Actionscript, what am I doing wrong?!?!?

            I've searched actionscript help to random the objects order on stage, but i have no ideia on how to use it.
            • 3. Re: Puzzel Game
              2m Level 2
              Hi,
              it seems to have a lot of problems here. So I would suggest to tackle them one by one.
              The first thing that comes to mind when seeing your code is the fact that you need to the user to be 100% accurate in dropping the objects.
              I would suggest that it's bad for to check if he has dropped the object inside a target area. You could define this area for example with an invisible rectangular object. Using "_droptarget" you should be able to determine if they'll checked hits the right place.
              That way the average user has a realistic chance of hitting the right base, without having to be pixel perfect.

              I hope this is a hint points to in the right direction with your first problem.
              If that's the case, we could try to attack the next problem.

              :-)
              • 4. Re: Puzzel Game
                Ricky2k7 Level 1
                Hey 2m...

                "would suggest that it's bad for to check if he has dropped the object inside a target area. You could define this area for example with an invisible rectangular object. Using "_droptarget" you should be able to determine if they'll checked hits the right place."

                I've done that, and when the user drags the object it snaps in the correct area.
                My main problem is that i can't go to another frame when all the objects are in place. :-S
                • 5. Re: Puzzel Game
                  2m Level 2
                  hi,

                  I'm sorry, now that you mention it I see what you did, and my misinterpretation too.
                  Here's what I would do:
                  If you have nine objects I would count up a variable "hits" (staring with the initial value of 0) one number each time an object snaps in its place. Whenever that happens, or to be precise. after that happened, I would check if "hits" is larger than eight. If that is the case I would send the play-head to the next frame.
                  That way it should be easier to track problems down.
                  • 6. Re: Puzzel Game
                    oiz2006
                    hi,
                    well i am doing this game with indiodoido but i allready tried that.i dont know if i have to declare that variable hits on the scene or inside of the mc timeline..and if i can do in the mc timeline i doesn' t go to the frame i what just stays there..plz help us
                    cumps
                    • 7. Re: Puzzel Game
                      2m Level 2
                      I'm not sure if I can find the time to guide you throug all of it, but I'll try to do my best.

                      Is the fla you posted still current, so that we can use it as you strarting point?
                      • 8. Re: Puzzel Game
                        oiz2006 Level 1
                        i think so..indiodoido have it in its homepage..if you can light me up in one thing..if you can view the fla from http:\\www.rld-i.com\puzzel.fla.if you can try to explain me a little i will try on my one..thankz for your time
                        • 9. Re: Puzzel Game
                          2m Level 2
                          Hi again,

                          I took a first glance at the fla, and it is all ver Flash "fourandhalf to five" style. Is the reason for that simply the fact that you found that kind of code somwhere in a tutorial, or is it that you just don't wna't to / have the time to do it in a more recent style?

                          To be more precise, have you heared of movieClip instance names, loops and arrays for example?

                          Don't ge me wromg, we can add the features you're talking about by keeping your style, but it will be more work and less learning in the end.

                          So should we start over (at least a bit) or continue from where we are?
                          • 10. Re: Puzzel Game
                            oiz2006 Level 1
                            i am a newbie in flash..i want to learn.this code was deliver to me by indio and i try to do something of it..i think maybe isn the best way.i know whats instances names and loops and arrays but not here..i only know C language..not actionscript.what is for you the best way to do this code?
                            • 11. Re: Puzzel Game
                              arunbe Level 1
                              hi
                              here we go.
                              the source is...
                              http://development.agriya.in/flash/puzzel.fla
                              • 12. Re: Puzzel Game
                                oiz2006 Level 1
                                oh sorry i didnt answer your question..lets start over..i want to do a puzzle simple where i put some mc on their correspodent areas and when all is in place it goes to another frame.
                                • 13. Re: Puzzel Game
                                  2m Level 2
                                  it seems arunbe has taken over, which is perfectly fine with me. He/She redid the whole thing. I don't understand why he/she chose to place more pieces on stage than necessary, but I'm sure you can solve that mystery.

                                  CU
                                  • 14. Re: Puzzel Game
                                    Ricky2k7 Level 1
                                    woh!! thanx arunbe for the new version of the puzzel, but i don't understand it :-S
                                    it works well, but it seems more complicated than the first version.
                                    Why did you use a for() to create the objects? It's more professional indeed, but for our project it's no that useful, because we need to use a image and slice it in 9 objects.

                                    About the released function:

                                    function released() {
                                    stopDrag();
                                    var id:Number = this._name.split("_")[1];
                                    var droped = this._droptarget;
                                    var droped_id:Number = droped.split("/area")[1];
                                    id = (Number(id)+1);
                                    trace(droped_id);
                                    if (Number(id) == droped_id) {
                                    totalDropped++;
                                    this._x = _root["area"+id]._x;
                                    this._y = _root["area"+id]._y;
                                    this.enabled = false;
                                    if (totalDropped == 9) {
                                    play();
                                    }
                                    } else {
                                    this._x = this.x;
                                    this._y = this.y;
                                    }
                                    }

                                    The code does what we need, but isn't there a simpler way?

                                    For example:
                                    this is the code that we have for every object of he puzzel:

                                    on (press)
                                    {
                                    this.startDrag();
                                    }

                                    on (release)
                                    {
                                    stopDrag();
                                    if (eval(this._droptarget) == _root.area1)
                                    {
                                    this._x = _root.area1._x;
                                    this._y = _root.area1._y;
                                    }
                                    }

                                    This simply does the drag and snap to its specific area.
                                    I tried to alter the code so that it sends a variable when the snap takes place:

                                    onClipEvent(load)
                                    {
                                    var obj1:Number = 0;
                                    }
                                    on (press)
                                    {
                                    this.startDrag();
                                    }
                                    on (release)
                                    {
                                    stopDrag();
                                    if (eval(this._droptarget) == _root.area1)
                                    {
                                    this._x = _root.area1._x;
                                    this._y = _root.area1._y;
                                    obj1 = 1;
                                    }
                                    }
                                    And in the actions layer on the main stage I added this code:

                                    function checkArea()
                                    {
                                    if (obj1==1 && obj2==2 && ... && obj9 ==1)
                                    {
                                    play();
                                    }
                                    }

                                    Why doesn't this work? What im i doing wrong? Is it everything? :-S
                                    Any suggestions 2m, oiz2006 ??
                                    • 15. Re: Puzzel Game
                                      Level 7
                                      IndioDoido,

                                      > woh!! thanx arunbe for the new version of the puzzel, but
                                      > i don't understand it :-S

                                      Wow, lots of people have chimed in, here! That's good, because I
                                      suddenly got swamped after my first reply and wasn't able to get back to
                                      this post right away (sorry about that!). I'm glad you weren't left
                                      hanging.

                                      At this point, I don't know if additional input from me would help or
                                      only make matters more confusing -- I certainly don't mean to give
                                      contradictory advice! :) For what it's worth, here's an article I wrote
                                      recently on building a jigsaw puzzle in ActionScript 2.0:

                                      http://www.communitymx.com/content/article.cfm?cid=8A2E0

                                      This is part one of a two-part series, and the first part is free. It
                                      includes the full source code for both parts, and the code is commented, so
                                      that should help. If you're interesed in part two, it's also free if you're
                                      a member of Community MX, and inexpensive if you aren't.


                                      David Stiller
                                      Adobe Community Expert
                                      Dev blog, http://www.quip.net/blog/
                                      "Luck is the residue of good design."


                                      • 16. Re: Puzzel Game
                                        oiz2006 Level 1
                                        well the part of inexpensive is the worse one..lol..gotta try to read this code.:-S
                                        • 17. Re: Puzzel Game
                                          Level 7
                                          oiz2006,

                                          > well the part of inexpensive is the worse one..lol..gotta
                                          > try to read this code.:-S

                                          Yes, there's a lot going on. It's not one of the beginner tutorials,
                                          for sure. ;) But it offers a good deal of discussion in regard to problem
                                          solving in general -- at least, that was my hope and intention while writing
                                          it: to present a fun way to learn about writing classes in ActionScript
                                          2.0. Five bucks (I think it's five, right?) buys eight pages of
                                          step-by-step instruction, with illustrations and full sample code. That's
                                          really not bad.

                                          Why don't you try a trial membership? In fact, that's free -- and it'll
                                          get you access to all sorts of tutorials.


                                          David Stiller
                                          Adobe Community Expert
                                          Dev blog, http://www.quip.net/blog/
                                          "Luck is the residue of good design."


                                          • 18. Re: Puzzel Game
                                            Ricky2k7 Level 1
                                            For example:
                                            this is the code that we have for every object of he puzzel:

                                            on (press)
                                            {
                                            this.startDrag();
                                            }

                                            on (release)
                                            {
                                            stopDrag();
                                            if (eval(this._droptarget) == _root.area1)
                                            {
                                            this._x = _root.area1._x;
                                            this._y = _root.area1._y;
                                            }
                                            }

                                            This simply does the drag and snap to its specific area.
                                            I tried to alter the code so that it sends a variable when the snap takes place:

                                            onClipEvent(load)
                                            {
                                            var obj1:Number = 0;
                                            }
                                            on (press)
                                            {
                                            this.startDrag();
                                            }
                                            on (release)
                                            {
                                            stopDrag();
                                            if (eval(this._droptarget) == _root.area1)
                                            {
                                            this._x = _root.area1._x;
                                            this._y = _root.area1._y;
                                            obj1 = 1;
                                            }
                                            }
                                            And in the actions layer on the main stage I added this code:

                                            function checkArea()
                                            {
                                            if (obj1==1 && obj2==2 && ... && obj9 ==1)
                                            {
                                            play();
                                            }
                                            }

                                            Why doesn't this work?
                                            • 19. Re: Puzzel Game
                                              Level 7
                                              IndioDoido,

                                              > I tried to alter the code so that it sends a variable when the
                                              > snap takes place:

                                              Not sure what you mean by "sends a variable," but let's look at the
                                              code.

                                              > onClipEvent(load)
                                              > {
                                              > var obj1:Number = 0;
                                              > }

                                              When this particular clip loads, it declares a local variable named obj1
                                              set to 0.

                                              > on (press)
                                              > {
                                              > this.startDrag();
                                              > }

                                              When pressed, this particular clip goes into dragging mode.

                                              > on (release)
                                              > {
                                              > stopDrag();

                                              When released, it stops dragging mode. But there's more ...

                                              > if (eval(this._droptarget) == _root.area1)
                                              > {
                                              > this._x = _root.area1._x;
                                              > this._y = _root.area1._y;
                                              > obj1 = 1;

                                              This clip's _droptarget property is evaluated as an object reference and
                                              compared to an object in the _root named area1. If they match, this clip's
                                              _x and _y properties are set to the corresponding properties of area1.
                                              Finally, obj1 (scoped to what? why not this.obj1?) is set to 1.

                                              > And in the actions layer on the main stage I added this code:
                                              >
                                              > function checkArea()
                                              > {
                                              > if (obj1==1 && obj2==2 && ... && obj9 ==1)
                                              > {
                                              > play();
                                              > }
                                              > }
                                              >
                                              > Why doesn't this work?

                                              Where is this checkArea() function referenced? I don't see anything
                                              invoking it.


                                              David Stiller
                                              Adobe Community Expert
                                              Dev blog, http://www.quip.net/blog/
                                              "Luck is the residue of good design."


                                              • 20. Re: Puzzel Game
                                                Ricky2k7 Level 1
                                                hi David

                                                "Where is this checkArea() function referenced? I don't see anything
                                                invoking it."

                                                Where do I do that?
                                                I don't know anything about actionscript language :-S

                                                • 21. Re: Puzzel Game
                                                  Level 7
                                                  IndioDoido,

                                                  >> "Where is this checkArea() function referenced? I don't
                                                  >> see anything invoking it."
                                                  >
                                                  > Where do I do that?

                                                  You do that wherever and whenever you want to. ;)

                                                  In this bit of code ...

                                                  on (press) {
                                                  this.startDrag();
                                                  }

                                                  ... you're invoking the MovieClip.startDrag() method. You referenced a
                                                  method when you chose to. :) Methods are just like functions -- they *do*
                                                  things -- but methods are associated with a class (e.g. the MovieClip
                                                  class), while functions are globally accessible.

                                                  > I don't know anything about actionscript language :-S

                                                  Seems like you ought to ground yourself in the basics, then, right? I
                                                  wouldn't consider trying to build a nice cabinet for my dining room without
                                                  learning carpentry.

                                                  This may help get you started:

                                                  http://www.quip.net/blog/2006/flash/tackling-the-actionscript-20-language-reference


                                                  David Stiller
                                                  Adobe Community Expert
                                                  Dev blog, http://www.quip.net/blog/
                                                  "Luck is the residue of good design."


                                                  • 22. Puzzel Game
                                                    Ricky2k7 Level 1
                                                    Simple question...

                                                    I have this code on a object that's on the stage:

                                                    on (press)
                                                    {
                                                    this.startDrag();
                                                    obj1 = 0;
                                                    }
                                                    on (release)
                                                    {
                                                    stopDrag();
                                                    if (eval(this._droptarget) == _root.area1)
                                                    {
                                                    this._x = _root.area1._x;
                                                    this._y = _root.area1._y;
                                                    obj1 = 1;
                                                    }
                                                    }

                                                    And this code on the main timeline of the stage:

                                                    if (obj1==1)
                                                    {
                                                    play();
                                                    }

                                                    Why doesn't the movie play?

                                                    i tryed to use _global.obj1 = 1; but it doesn't work either :-S
                                                    pleaaassseee heeeeeeelllllllpppppp!!!!