Tuesday, November 15, 2011

Flash Develop


I've just started using Flash Develop, not enough to give a decent review, but enough to say, 'Hey... I kinda' like this!' but it didn't start out so well... I figured, what better way to dive back into AS3 and get used to Flash Develop, than by going through Michael James William's AS3 Avoider Game Tutorial? So I started on section 1, everything was going great... FD booted right up, it asked me to create a package, and... oh crud, which one should I pick? AS3 Project? Flash IDE project? AS3 with Preloader? HaXe? ...what the heck is HaXe? I definitely don't want Haxe, I guess... right? No, no, course not...
Would you believe Michael helped me again? I found this post over on Active Tuts+ which explained which one was for me.

OK, Really getting started now
Ok, so my project is open and I jump right into section 1 of the AS3 tutorial. I scan down because a lot of the prep doesn't seem to apply... then I make my first enemy (using the Flash IDE), export the SWC, and import it into FD (the whole reason I jumped into FD in the first place - but that's for another story)
I'm just humming along now! I create a new class: Enemy.as and then I press Ctrl+Enter to test my 'game'!
...wait, there's no enemy on the screen! Where the heck is the enemy I just created? I check, double-check, TRIPLE check my spelling. I copy and paste from the tutorial.
Will. Not. Appear.
I remove the AS file from my project and add that code to my main AS file and now my enemy is there. ...huh?
Time to hit Google again... thankfully I found this post on One Giant Medias website before I went completely bald from frustration. It notes:
Issue:
Using custom classes with the same names as linkage library movie clips in Flash IDE would trace output but not show up on stage
and then it goes on to explain how to get it working.
So, I went back to the Flash IDE, right-clicked my Enemy in the library and chose Linkage...
I changed the class to FL_Enemy, saved, and published the file.
Time to go back to Flash Develop, now open up that Enemy.as class file and change
public class Enemy extends MovieClip
to
public class Enemy extends FL_Enemy
...by the way, you don't have to pick FL_Enemy for the library class, it can be anything, but appending FL_ is a suggestion from the OneGiantMedia blog article. Of course, you'd have known that if you clicked the link above!

...back to programming!
-Bigfoot




Friday, September 11, 2009

Update!


It's been a while, thought it was time to post an update. Life's been exciting lately. I'm about to find out whether my wife is pregnant with a boy or a girl... I got laid off from my job... worked two new jobs (though only kept the second one...), and received two other offers (it's nice to feel wanted!)... and found out how to make a killer blended coffee drink! Ok, that last was the least exciting, but I'm going to fill you in on the details anyways...

What you'll need...


  • A blender (we have a 'Magic Bullet')

  • A pot of coffee (we used Wal-Mart brand)

  • Ice cube trays (these came with the apartment, believe it or not)

  • Sugar (sweeten to your taste, I like a little, my sweetie loves it sweeter!)

  • Milk (We've made it with both 1% and evaporated milk - both good!)

  • Some dark chocolate (optional)

  • First, make a pot of coffee... After it's cooled down, pour the brewed coffee into ice cube trays and freeze overnight.
    The next morning, put some coffee cubes, sugar, milk, and chocolate into the blender and blend until smooth. ...That's it! Try it!


    Ok, on to other stuff... I've been working on Tonypa's tile based game flash tutorials aaaand the jury is still out on whether I like them or not. I'll finish them, and then maybe I'll feel more qualified to give my opinions...
    You'll just have to come back!

    Tuesday, August 11, 2009

    Getting rid of duplicate lines of code



    I just finished one of MJW's sh'm'up tutorials and by the end I had multiple lines that were duplicates of each other. For example:
    1. {

    2. removeChild( bullet );

    3. bullets.splice( j, 1 );

    4. }


    While this used to be okay - I just wanted working code! - Now, after these tutorials I'm spoiled. Some would say a better (though very beginner!) programmer. I feel like I need to compact it and clean it up as much as possible.
    So I created a public function called removeClip (first it was removeEnemy, then I figured I could use it for the bullets too, and maybe other things later!) and passed it three variables:
  • instance of the clip I wanted to remove.
  • the position it was in the array
  • and, the array name.

    Tada!
    1. public function removeClip( movieClip:MovieClip, i:int, array:Array ):void

    2. {

    3.     removeChild( movieClip );

    4.     array.splice( i, 1 );

    5. }



    Then I just went back through AvoiderGame.as and replaced all those lines that removed the bullet / enemy with:
    removeClip( enemy, i, army );
    or
    removeClip( bullet, j, bullets );

    Michael, thanks for teaching us how to code.

    EDIT: MJW posted a comment on trimming down my code even more that I'd like to share! (Especially in case you don't read the comments...)

    He wrote: "I'm not sure if you know this, but all arrays have a method, .indexOf( item ), that returns the index of the item specified (or -1 if the item is not in the array).

    So you can write "array.splice( array.indexOf( movieClip ), 1 )", for example. This way you don't have to pass the index of the item through to the function each time!
    "

    I've used his suggestion, and changed my removeClip function to this:
    1. public function removeClip( movieClip:MovieClip, array:Array ):void

    2. {

    3.     removeChild( movieClip );

    4.     array.splice( array.indexOf( movieClip ), 1 );

    5. }


    I guess if you wanted, you could also make a check to make sure it was part of that array before trying to splice, like this:
    1. public function removeClip( movieClip:MovieClip, array:Array ):void

    2. {

    3.     removeChild( movieClip );

    4.     if( array.indexOf( movieClip ) != -1  )

    5.     {

    6.         array.splice( array.indexOf( movieClip ), 1 );

    7.     }

    8. }


    Anyways, it might not seem like a lot at first. You're only slimming it down by one small variable. But that's one less variable for every bullet that leaves the screen, or hits an enemy, plus every enemy that gets hit, or leaves the screen, and in a much bigger game it would really start adding up.

    A little more information about it here from Senocular
  • Thursday, August 6, 2009

    MJW Avoider Game ep11ch1



    Alrighty-- Another challenge! I already wrote below about my fun with isNaN during this challenge. But let me try to document what I did for the challenge itself. Won't be too long...

    Staying in the GameOverScreen.as file, I added the following to the constructor. (I called my array bestScoreArray) I wanted to check if the array was undefined or empty, and if so, create it.
    1. if( isNaN(sharedObject.data.bestScoreArray) )

    2. {

    3.     sharedObject.data.bestScoreArray = new Array();

    4. }



    Then, I figured I'd plug information when the final score was set. So down in the setFinalScre function:
    1. else if( scoreValue > sharedObject.data.bestScore )

    2. {

    3. //  sharedObject.data.bestScore = scoreValue;

    4.     sharedObject.data.bestScoreArray = [scoreValue, sharedObject.data.totalGames, "Test"];         

    5. }


    I'm grabbing three pieces of information and sticking it in an array -- score, total number of games played when that score was reached, and an arbitrary string of text just to test.

    Ok, now I need to make sure it's working, so I threw this down below in the same 'setFinalScore' function. It will loop through the array and 'trace' every item to the output window.
    1. for (var i:int = 0; i < sharedObject.data.bestScoreArray.length; i++ )

    2. {

    3.     trace( i, sharedObject.data.bestScoreArray[i] );

    4. }



    Now run it.

    D'oh! Didn't work... why not? Looking back through my code I realized this was wrong:
    1. if( isNaN( sharedObject.data.bestScoreArray ) )



    Can you spot why? Because we're creating an array... so it's NEVER going to be a "number" (isNaN checks if something is 'not a number')

    So, change that to this, and try again:
    1. if( sharedObject.data.bestScoreArray == null )

    2. {

    3.     sharedObject.data.bestScoreArray = new Array();

    4. }



    Voila! Should work now. If you have any problems, let me know.

    Wednesday, August 5, 2009

    Master! Master! Where's the dreams that I've been after...

    I'm an Experts-Exchange fan. It's a great place to get quick help on technology problems. Well, how kewl is this? I got the rank of "Master" on there, and now they're sending me a free t-shirt. Not often that places actually do give away something free, they didn't even ask for s/h... :)

    Bigfoot
    Master50,000 Expert Points
    Windows XP Operating System


    Wow, and Blogger.com totally screwed up the formatting on that signature...

    What is isNaN()?



    So earlier I worked through MJWs Avoider Game Tutorial Chapter 11 and got to the challenges. I was excited! I wanted to save some data to the local computer too! So my first addition was going to be adding how many times the player played my game. Sounds easy enough, it was using the same idea as saving the highest score, right?

    Well, I figured GameOverScreen.as was as good a place as any -if not better!- to do this. So I added the following lines:

    1. sharedObject.data.totalGames += 1;

    2. trace( sharedObject.data.totalGames ); 



    But my output didn't read "1" - it said NaN. Whaaaat?
    So I threw in an IF statement:
    1. if( sharedObject.data.totalGames == null )

    2. {

    3.     sharedObject.data.totalGames = 0;

    4. }


    Haha! MJW helped me to learn to code!
    ...only problem was: It didn't work. My output still read NaN.
    Not one to just ask a question and wait for the answer (sorry, I told you to post a comment on MJW's site if you had a question... I'm a hypocrite) I browsed to Google and searched for an answer.

    The answer to my problem was isNaN! Here's what I put in my code:
    1. if( isNaN(sharedObject.data.totalGames) )

    2. {

    3.     sharedObject.data.totalGames = 0;

    4. }

    5. sharedObject.data.totalGames += 1;

    6. trace( sharedObject.data.totalGames );     



    Now that works! I didn't even have to 'import' anything... though I did search for that because I accidentally put isNan (note the lower case 'n') in my code and got an error.

    So there you go... isNaN()

    Monday, August 3, 2009

    Michael asked for it...



    MJW left a comment asking if I was going to post my game anytime soon. So by, umm... popular demand (Hey, 50% of my blogs' commenters asked for it!!) - here it is!

    The game gets difficult REALLY quick. But I don't really expect you to play it long. I'm just trying to get the basics down right now.



    http://bigfoot-avoidergame.googlecode.com/files/Avoider.swf

    Comments, banter, criticism? Close your browser...
    Want to lavish praise? Leave it in the comment section!
    Kidding... I want to hear it all - leave me a comment if you play. We'll call it "Comment-Ware"