Second stage of coding the Piggy Bank flash project…..

Week 9~~~
At the first stage of coding the project, I added code for each coin to make them both are clickable and draggable.After the Monday class, Ruben teach me a method, so I don’t need to write the some code five time for those coins.
The code are:
//for loop
for (var i=0; i< coin_mc.length; i++){
//Listener for click and drag coins
trace(coin_mc[i]+" test");
this[coin_mc[i]].buttonMode = true;
this[coin_mc[i]].addEventListener(MouseEvent.CLICK, clickHandler);
this[coin_mc[i]].addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener);
this[coin_mc[i]].addEventListener(MouseEvent.MOUSE_UP, mouseUpListener);
}

//functions for click and drag coins
function clickHandler(event:MouseEvent):void {
trace("You clicked the Coin");
}
function mouseDownListener(event:MouseEvent):void {
coinName = MovieClip(event.currentTarget);
trace(coinName);
coinName.startDrag();
}

As I mention before(my Previous post) I have to use addChild and removeChild to control the coins disappear then add another one at the original location to make this application can run as many time as it reach the max amount, but it seems too difficult to me at this stage. I have tried another method—set the x and y value for the each coins. It means when the mouse release the coins will go back to their original location.
The code that I have been used:

if(coinName.hitTestObject(pig_mc)){
if(coinName == coin10_mc){
totalCoins +=0.10;
coinName.x=100;
coinName.y=280;}
}
else if(coinName == coin20_mc){
totalCoins +=0.20;
coinName.x=150;
coinName.y=280;}
else if(coinName == coin50_mc){
totalCoins +=0.50;
coinName.x=200;
coinName.y=280;}
else if(coinName == coin1_mc){
totalCoins +=1.0;
coinName.x=250;
coinName.y=280;}
else {totalCoins +=2.0;
coinName.x=300;
coinName.y=280;}
money_txt.text = "You have:"+ totalCoins +"dollars";

It's work, but still got some errors…
The next stage is storing the data using share object or write to a text file…

~ by wingcl on September 21, 2009.

3 Responses to “Second stage of coding the Piggy Bank flash project…..”

  1. Hey, I found your blog in a new directory of blogs. I dont know how your blog came up, must have been a typo, anyway cool blog, I bookmarked you. :) :)

  2. I don’t know If I said it already but …This blog rocks! I gotta say, that I read a lot of blogs on a daily basis and for the most part, people lack substance but, I just wanted to make a quick comment to say I’m glad I found your blog. Thanks, :)

    A definite great read….

  3. X3Bucb jezxtsdkaddo, [url=http://uwfhvszzvsbn.com/]uwfhvszzvsbn[/url], [link=http://xcwxtsddpuhz.com/]xcwxtsddpuhz[/link], http://ulplxirukuaa.com/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.