flash action-script 3保存并加载

时间:2015-12-13 15:20:29

标签: actionscript-3 flash

嘿伙计我正在使用flash动作脚本3进行游戏,我用我的代码到达了我已经添加了一个完美的静音按钮,但我想做的是保持静音而在游戏中即使我关闭游戏重新打开它。

另一件事是我想要保存游戏,即使我关闭它并按照我离开它的方式重新打开它。

所以请帮助我们这里的人是我的代码

var foundObjects:Number=0
var triesNumber:Number=0
stop()

import flash.net.SharedObject;
var mySo:SharedObject = SharedObject.getLocal("squaresGame");
if(mySo.data.levelNumber==null)
mySo.data.levelNumber="0.01"
//mySo.data.levelNumber
var level:Number=mySo.data.levelNumber
var sTransform1:SoundTransform = new SoundTransform(1,0);


function setMute1(vol){
   sTransform1.volume = vol; 
   SoundMixer.soundTransform = sTransform1;
 }

levelText.text=(level*100).toString()
var turkeyArray:Array = new Array();
turkeyArray[1] = m1;
turkeyArray[2] = m2;
turkeyArray[3] = m3;
turkeyArray[4] = m4;
turkeyArray[5] = m5;
turkeyArray[6] = m6;
turkeyArray[7] = m7;
turkeyArray[8] = m8;
turkeyArray[9] = m9;

m1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
m2.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
m3.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
m4.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
m5.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
m6.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
m7.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
m8.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
m9.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{ 
event.currentTarget.play()
testFoundObject(event.currentTarget)

}


function testFoundObject(mc:Object):void
{
if(mc.hitTestObject(apple1) || mc.hitTestObject(apple2)||mc.hitTestObject(apple3))
    {
    foundObjects++
    applesquresound.play()
    }
    else
    emptysquresound.play()
    trace(foundObjects)

triesNumber++
if(triesNumber>=3)
    if(foundObjects>=3)
        {
            level+=0.01
            mySo.data.levelNumber=level.toFixed(2)
            levelText.text=(level*100).toString()
            yes.play()
        }
    else{
        no.play()
        }

 } 





addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);

function fl_EnterFrameHandler(event:Event):void
{
if(m1.alpha<1)
    for(var counter:Number=1;counter<=9;counter++){
        MovieClip(turkeyArray[counter]).alpha+=level
    }

}


button_1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);

function fl_MouseClickHandler_2(event:MouseEvent):void
{
gotoAndPlay(1)
} 



toggleMuteBtn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_3);

function fl_MouseClickHandler_3(event:MouseEvent):void
{
if(Mute1 == false) {
    Mute1 = true;
    setMute1(1);
toggleMuteBtn.gotoAndStop(1)
 } else {
    Mute1 = false;
    setMute1(0);
toggleMuteBtn.gotoAndStop(2)
    }

} 



var locationMC:MovieClip=MovieClip(turkeyArray[randomRange(1,9)]);
apple1.x=locationMC.x
apple1.y=locationMC.y

locationMC=MovieClip(turkeyArray[randomRange(1,9)]);
apple2.x=locationMC.x
apple2.y=locationMC.y
while(apple2.hitTestObject(apple1) || apple2.hitTestObject(apple3))
{locationMC=MovieClip(turkeyArray[randomRange(1,9)]);
apple2.x=locationMC.x
apple2.y=locationMC.y
}

locationMC=MovieClip(turkeyArray[randomRange(1,9)]);
apple3.x=locationMC.x
apple3.y=locationMC.y
while(apple3.hitTestObject(apple1) || apple3.hitTestObject(apple2))
{locationMC=MovieClip(turkeyArray[randomRange(1,9)]);
apple3.x=locationMC.x
apple3.y=locationMC.y
} 


function randomRange(minNum:Number, maxNum:Number):Number 
{
return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
}

1 个答案:

答案 0 :(得分:0)

您可以使用SharedObject类来存储和加载有关声音静音的信息。正如我在您的代码中看到的那样,您已经使用此类来存储levelNumber,所以我认为这对您来说不是一个挑战。