actionscript-3flashcookiesshared-objectslocal-shared-object

Something like cookies in Flash/ActionScript


i need to implement something like a cookie in a flash file....and i dont have a clue about ActionScript. Basically it is a video with a mute/unmute button. If i mute the video and refresh the browser it is not muted again.So i need to persist the mute status somehow.

Here is my complete ActionScript File:

import flash.net.SharedObject;
var a:Boolean = false;

var cookie:SharedObject = sharedobject.getLocal("muted");
if (cookie.data.muted == true) {
    SoundMixer.soundTransform = new SoundTransform(0);
    Object(root).ton_btn.gotoAndStop(2);
}

ton_btn.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);

function fl_MouseOverHandler(event:MouseEvent):void
{
 Object(root).ton_btn.buttonMode = true;
 Object(root).ton_btn.useHandCursor = true;
}

ton_btn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

function fl_MouseClickHandler(event:MouseEvent):void
{
 if (! a)
 {
    var muteStatus:Boolean = true;
    cookie.data.muted = muteStatus;
    SoundMixer.soundTransform = new SoundTransform(0);
    Object(root).ton_btn.gotoAndStop(2);
    trace(a);
 }
 else
 {
    var muteStatus:Boolean = false;
    cookie.data.muted = muteStatus;
    SoundMixer.soundTransform = new SoundTransform(1);
    Object(root).ton_btn.gotoAndStop(1);
    trace(a);
 }
 a = ! a;
}

This is not working, now my mute button is flickering....it seems, that the if clause is constantly executing. Thanks for any tip, hint or link in advance. ;)

Regards Nils

Edit: So stupid...it was just a typo.

var cookie:SharedObject = sharedobject.getLocal("muted");

must be:

var cookie:SharedObject = SharedObject.getLocal("muted");

Now it is working.


Solution

  • I recommend following opensource that is popular ActionScript3.0 Cookie Frameworks. In general, two kinds of cookies in with the framework is known. Please see under open source. Solve your problem more quickly, you may give. Number 1 is a only Sourcode and Tutorial, Number 2 is a full of Frameworks.

    1. Read and Write and Edit using a SharedObject

    2. Actionscript3 Cookie Util