2012.10.02道具獲取(說明)PS只有場景的程式
import flash.display.MovieClip;
import flash.media.Sound;
import flash.events.Event;
import flash.events.MouseEvent;
var meat:MovieClip;
var money:MovieClip;
var explain:MovieClip;
var sound:Sound;
creatmeat();
creatmoney();
stage.addEventListener(Event.ENTER_FRAME,loop);
function loop(e:Event)
{
if(meat.flag == false)
creatmeat();
if(money.flag == false)
creatmoney();
}
//
function creatmeat()
{
meat = new mt();
meat.scaleX = 0.6;
meat.scaleY = 0.6;
meat.x = Math.floor(Math.random()*350+50);
meat.y = Math.floor(Math.random()*250+50);
stage.addChild(meat);
meat.addEventListener(MouseEvent.MOUSE_OVER,movin1);
meat.addEventListener(MouseEvent.MOUSE_OUT,movout);
meat.addEventListener(MouseEvent.CLICK,pick1)
}
function movin1(e:MouseEvent)
{
explain = new hint();
explain.gotoAndStop(1);
if(meat.x > 275)
{
if (meat.y<200)
{
explain.x = meat.x - meat.width/2 - explain.width/2;
explain.y = meat.y + meat.height/2 + explain.height/2;
}
else
{
explain.x = meat.x - meat.width/2 - explain.width/2;
explain.y = meat.y - meat.height/2 - explain.height/2;
}
}
else
{
if (meat.y < 200)
{
explain.x = meat.x + meat.width/2 + explain.width/2;
explain.y = meat.y + meat.height/2 + explain.height/2;
}
else
{
explain.x = meat.x + meat.width/2 + explain.width/2;
explain.y = meat.y - meat.height/2 - explain.height/2;
}
}
stage.addChild(explain);
}
function movout(e:MouseEvent)
{
stage.removeChild(explain);
}
function pick1(e:MouseEvent)
{
stage.removeEventListener(MouseEvent.CLICK,pick1);
meat.play();
sound = new eat();
sound.play();
}
//
function creatmoney()
{
money = new coin();
money.scaleX = 0.2;
money.scaleY = 0.2;
money.x = Math.floor(Math.random()*350+50);
money.y = Math.floor(Math.random()*250+50);
stage.addChild(money);
money.addEventListener(MouseEvent.MOUSE_OVER,movin2);
money.addEventListener(MouseEvent.MOUSE_OUT,movout2);
money.addEventListener(MouseEvent.CLICK,pick2)
}
function movin2(e:MouseEvent)
{
explain = new hint();
explain.gotoAndStop(2);
if(money.x > 275)
{
if (money.y<200)
{
explain.x = money.x - money.width/2 - explain.width/2;
explain.y = money.y + money.height/2 + explain.height/2;
}
else
{
explain.x = money.x - money.width/2 - explain.width/2;
explain.y = money.y - money.height/2 - explain.height/2;
}
}
else
{
if (money.y < 200)
{
explain.x = money.x + money.width/2 + explain.width/2;
explain.y = money.y + money.height/2 + explain.height/2;
}
else
{
explain.x = money.x + money.width/2 + explain.width/2;
explain.y = money.y - money.height/2 - explain.height/2;
}
}
stage.addChild(explain);
}
function movout2(e:MouseEvent)
{
stage.removeChild(explain);
}
function pick2(e:MouseEvent)
{
stage.removeEventListener(MouseEvent.CLICK,pick2);
money.play();
sound = new sou();
sound.play();
}