24 Replies Latest reply on Jun 7, 2009 3:54 PM by merkk

    flash newbie - good intro lessons etc

    merkk Level 1

      hi all,

      very new to flash (not to web programming though).

       

      I volunteered to work on a small project (at least i hope it's small).

       

      I need to create a form where someone can upload a poker game that was played, and then animate that poker hand to actually show the game being played.

       

      So what i think i need to know, is how to get flash to read a form field (either an html form or a flash form, which ever would be easier) and then basically how to take an image and move it around on the screen. For example, if the player uploads a poker hand, i need to make the cards the player used appear in his hand, or make some chips appear in his hand if he won a bet, or place chips on the center of the table if he placed a bet.

       

      Can anyone suggest a good place to start learning how to do this? I dont care if it's action script 2 or 3 - i assume learning 3 would be better since thats the newest but i dont really care.

       

      and just to be clear, i dont need to actually make a game, i'm just basically making a movie to show a game that was played with the info the hands played submitted via form.

       

      thanks in advance for any advice.

        • 1. Re: flash newbie - good intro lessons etc
          kglad Adobe Community Professional & MVP

          that does not sound like a newbie project.

           

          but to start wouldn't be hard.  you can create a form in flash by adding input textfields to the stage.  i would think you'll want to add 5 or more (one for each card in the player's hand).

           

          you can also add a button to the stage that the player would click when they've entered data for all their cards.  then the fun begins.

          • 2. Re: flash newbie - good intro lessons etc
            merkk Level 1

            yea, i figured out how to add form fields to the page - took a little head scratching but i think i have that figured out.

             

            What i need to know now though is how do i access the values in those fields?

            And how do i make an image appear at a specific location? Eventually i'll want to make it more animated where the card might slide over to the players hand. But for this first initial attempt, having the cards or chips just appear where i want them is good enough.

             

            So any tips on how to read flash form fields and how to make an image appear/disappear at specific locations? I think those are the two main tasks involved in this right now.

             

            Oh and i'm using flash cs4 - if it's easier with cs3 i'll install the cs3 trial just to get this done.

             

            thanks for any tips

            • 3. Re: flash newbie - good intro lessons etc
              kglad Adobe Community Professional & MVP

              you should assign an instance name to each textfield (click on the textfield and in the properties panel enter a name, say tf1).  you can then access the text written into the textfield by referencing:

               

              tf1.text

              1 person found this helpful
              • 4. Re: flash newbie - good intro lessons etc
                merkk Level 1

                ok cool. So i'd create the form fields, create a submit button which i assume would be assigned to some as function which would then read all the form fields. Once i've read all the fields, I'd then have to play the 'movie' of the poker hand being played.

                 

                So lets say I have 54 images - one for each card in the deck. And a couple of images for different value poker chips.

                 

                How do i make a specific set of cards and chips appear or disappear at a specific location?

                 

                Would it be as simple as something like:

                 

                KingHeart.visible = true;

                Kingheart.LocationX = 123

                KingHeart.LocationY = 456;

                 

                Assuming the king of heart image was named KingHeart

                 

                thanks again for the help

                • 5. Re: flash newbie - good intro lessons etc
                  kglad Adobe Community Professional & MVP

                  it would work better if you assign each card a class (assuming you're using as3, which it appears you are) or assign a linkage id (if you're using as2).  which are you using?

                  • 6. Re: flash newbie - good intro lessons etc
                    merkk Level 1

                    I was planning on using as3 - figured if i was going to learn action script might as well start with the latest version.

                     

                    so when you say class - is that as in standard OO programming? i.e. there would be one class for all 54 cards, rather then 54 seperate classes?

                     

                    Was I close in how i would make the images appear and disappear at specific locations?

                     

                    thanks again

                    • 7. Re: flash newbie - good intro lessons etc
                      kglad Adobe Community Professional & MVP

                      so, right click on the king of hearts movieclip in your library, click properties, tick export for actionscript and in the class textfield type something like KingHearts.  likewise for the rest of the cards.

                       

                      then if you want to display a hand of 5 cards you could use:

                       

                      var card1:KingHearts=new KingHearts();

                      var card2:JackSpades=new JackSpades();

                      var card3:FourClubs=new FourClubs();  // don't start object names with a number in flash

                      var card4:KingDiamonds=new KingDiamonds();

                      var card5:FourSpaces=new FourSpaces();

                       

                      addChild(card1);

                      addChild(card2);

                      addChild(card3);

                      addChild(card4);

                      addChild(card5);

                       

                      card1.x=100;

                      card1.y=100;

                      card2.x=card1.x+card1.width+5;

                      card2.y=100;

                      card3.x=card2.x+card2.width+5;

                      card3.y=100;

                      card4.x=card3.x+card3.width+5;

                      card4.y=100;

                      card5.x=card4.x+card4.width+5;

                      card5.y=100;

                      1 person found this helpful
                      • 8. Re: flash newbie - good intro lessons etc
                        merkk Level 1

                        ah ok, so i do make a class for each card and then create an instance of that class in order to use the card. got it.

                         

                        And from the code you listed below, looks like that'll lay out the cards one on top of the other, but shifted over to the side a little so you can see all the cards layed out.

                         

                        if i want to get rid of the card, do i just destroy it? Or move set the x/y position to somewhere off stage? I assume removing it completely is the best way to go to free up resources etc.

                         

                        thanks again for your help with this.

                        • 9. Re: flash newbie - good intro lessons etc
                          kglad Adobe Community Professional & MVP

                          the cards will be side-by-side with no overlap.  you can play with the x,y properties to suit your needs.

                           

                          to remove card1 use:

                           

                          removeChild(card1);

                          card1=null;

                          • 10. Re: flash newbie - good intro lessons etc
                            merkk Level 1

                            ok, thanks. I think that should give me something to start working with.

                             

                            Hopefully i wont have any more questions for you - at least for a little while

                             

                            thanks again for the help.

                            • 11. Re: flash newbie - good intro lessons etc
                              merkk Level 1

                              ok, looks like i lied. I do have one more question.

                               

                              Someone sent me a adobe illustrator file containing images of all the cards of the deck. He sent me one file which contains all the cards, i think each card is in it's own layer.

                               

                              I do not have AI installed.

                               

                              Is there some way for me to import all the cards as seperate images?

                               

                              thanks

                              • 12. Re: flash newbie - good intro lessons etc
                                kglad Adobe Community Professional & MVP

                                create a new movieclip and while in that movieclips timeline click file/import/import to stage.  see what you get.

                                • 13. Re: flash newbie - good intro lessons etc
                                  merkk Level 1

                                  hmm i was close. I was trying to import it to library.

                                   

                                  When i do it to stage, i can access each card. They are all on top of each other so i have to hide them all and then just show one at a time.

                                   

                                  do i then want to convert it to symbol?

                                   

                                  If i select convert to symbol, i then have a choice of button, graphic or movie clip. I assume i want movie clip.

                                   

                                  And under advanced settings, there's an option to export for actionscript, which i assume i should check.  There's also a check box for

                                  'export in frame 1' - not sure what that is.

                                  Also wants me to set the class, which in this case i assume would be KingHearts, KingClubs etc etc and bass class is set to flash.display.MovieClip.

                                   

                                  Also two checkboxes for export or inport for runtime sharing.

                                   

                                  If i just have to click on each one, convert to symbol, enable AS and name the class, i can do that.

                                   

                                  thanks

                                  • 14. Re: flash newbie - good intro lessons etc
                                    kglad Adobe Community Professional & MVP

                                    once you have them all on-stage, click the frame that contains them and over the image right click and click distribute to layers.  each card should be in its own layer.  now right click each one and click convert to symbol/movieclip, tick export for actionscript and assign a class name.

                                     

                                    you don't need to do any runtime import/export so leave those unchecked.

                                    • 15. Re: flash newbie - good intro lessons etc
                                      merkk Level 1

                                      a quick ( i hope) question.

                                       

                                      I saw the code you showed for accessing the form field values. Can flash also access a regular html form field? I actually already have most of a form finished in html. So it would save me some time if i didnt have to create a flash form but could instead just have the html form post to the flash/actionscript file.

                                       

                                      Is it possible to do that? If so, can you tell me what code i would use to access the html form fields? It's pretty much a combo of all html form fields - textbox, dropdown, checkbox, and radio button.

                                       

                                      thanks

                                      • 16. Re: flash newbie - good intro lessons etc
                                        kglad Adobe Community Professional & MVP

                                        it's possible but there's no point to having the form call a javascript function (on submit) that then calls an actionscript function that then calls php or some other server-side script.

                                         

                                        the form (on submit) may as well call the php or some other server-side script directly.  nothing's gained by using flash in that process.

                                        • 17. Re: flash newbie - good intro lessons etc
                                          merkk Level 1

                                          I'm a bit confused by your response.

                                           

                                          Why/how would i use php or any other script for this? There is nothing server side going on here, other then playing the flash movie of the card game. I'm not saving anything into a database (yet) or anything like that. at this point all it is is someone filling out a form with the hands played in a card game, and then having a simple flash movie show those hands being played.

                                           

                                          Are you saying there's a way to do that using php/asp.net instead of action script? (I'm going to feel really stupid if that was the question i should have asked from the beginining).

                                           

                                          thanks

                                          • 18. Re: flash newbie - good intro lessons etc
                                            merkk Level 1

                                            hi again,

                                             

                                            I was just wondering if you could explain your last post? I was a little confused by that. I've actually started getting some of this working thanks to the help you gave me.

                                             

                                            I'm at the point now where i need to read the values submitted on the form and then display the appropriate images on screen. I already have an HTML page layed out with all the form fields on it. i was wondering if could use this page to allow someone to fill out their info, submit it and then read the values from the form and display the flash movie.

                                             

                                            I know how to read form values from a flash form thanks to the sample code you showed me. But can i read form values from an html form? Do i just have the html form post to the .fla file?

                                             

                                            thanks

                                            • 19. Re: flash newbie - good intro lessons etc
                                              kglad Adobe Community Professional & MVP

                                              i'm confused by my response, too.  either one of your messages was changed or i was responding to someone elses thread and inadvertently responded in your thread.

                                               

                                              in any case, you can use an html form to communicate with javascript and you can use the externalinterface class to communicate between javascript and actionscript.

                                              • 20. Re: flash newbie - good intro lessons etc
                                                merkk Level 1

                                                thanks for the reply. So sounds like one way or another I cant just use the html form. Having to write up javascript to read the form values and then write as code to read the js code seems a little silly to me.  I should probably just make a flash form rather then go through all these extra intermediary steps. Just seems surprising to me that flash can't read a simple html form. Or at least not from a POST anyhow. I did read that i could use GET - append all the form values in a url query string. I'll have to decide which approach seems the most efficient.

                                                 

                                                thanks for the help again

                                                • 21. Re: flash newbie - good intro lessons etc
                                                  kglad Adobe Community Professional & MVP

                                                  i agree with the conclusion in the middle of your above paragraph.  and, i think, the same conclusion is valid if you try to pass the query string.

                                                   

                                                  you must have some aversion to creating a form in flash.  and that's hard to understand because it's much easier to create a form in flash than it is to create a form in html.

                                                  • 22. Re: flash newbie - good intro lessons etc
                                                    merkk Level 1

                                                    granted i haven't created a full form in flash - i've only created 1 or 2 text fields to test with. But it seems like there are more steps involved in creating the flash form. Could just be because i am new to it so it just seems to take longer since i'm still getting used to it.

                                                     

                                                    The main reason though i wanted to try and use an html form is that i already have an html form i can use so it would save me some work if i could use that instead of having to create one. Oh well, this is good enough. I just need to sit down, start making the form and start writing the code.

                                                     

                                                    The only part of the code that I'm unclear on now (but i think i can figure it out) is how I can make an animation (a tween i think its called) of a card and then in the code apply that tween to whatever card i want. I assume that can be done, since i cant imaging i have to make an animation of the same thing for each individual card.

                                                     

                                                    I'm reading through learning action script 3 - i'm sure there's a chapter in there on this that i just haven't gotten to yet

                                                     

                                                    thank you again for your help

                                                    • 23. Re: flash newbie - good intro lessons etc
                                                      kglad Adobe Community Professional & MVP

                                                      that's about it.  add input textfields to the stage, give them instance name and place a label near each textfield so the user knows what's expected in that textfield.

                                                       

                                                      you can then use the textfield's text property to retrieve what the user entered.  for example, if you have a textfield labeled card1TF and the user enters "ace of clubs",

                                                       

                                                      card1TF.text

                                                       

                                                      would contain the string "ace of clubs"

                                                      • 24. Re: flash newbie - good intro lessons etc
                                                        merkk Level 1

                                                        yup, i used that from your previous example