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.
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.
Read and Write and Edit using a SharedObject
Actionscript3 Cookie Util
Related
Currently I am trying to use JAWS screen reader to make a .swf I have created easier to those who need this sort of software.
I so far have been able to set the name and tab-indexes for two movie-clips.
I was wondering if anyone knew how to get the screen reader to read the names or descriptions of these movie-clips?
import flash.accessibility.AccessibilityProperties;
stop();
setupJAWS();
/////////////////////---JAWS---//////////////////////////////////////
function enable( mc:* ) {
trace("Enabled");
var _accessClip = mc;
_accessClip.accessibilityProperties.silent = false;
_accessClip.tabEnabled = true;
}
function disable( mc:* ) {
var _accessClip = mc;
_accessClip.accessibilityProperties.silent = true;
_accessClip.tabEnabled = false;
}
function setupJAWS(){
trace("SETTING UP");
this.Text58.accessibilityProperties = new AccessibilityProperties();
this.Text58.accessibilityProperties.name = "TEXT1";
this.Text58.tabIndex = 2;
enable(this.Text58);
this.Text59.accessibilityProperties = new AccessibilityProperties();
this.Text59.accessibilityProperties.name = "TEXT2";
this.Text59.tabIndex = 3;
enable(this.Text59);
Accessibility.updateProperties();
stage.focus=Text58;
}
If you don't know that answer to this could you please up vote the question as I really need this answered, Thanks in advance. :)
stop();
var mySound:Sound = new MyFavSong();
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0;
myChannel = mySound.play();
pause_btn1.addEventListener(MouseEvent.CLICK, onClickPause);
function onClickPause(e:MouseEvent):void
{
lastPosition = myChannel.position;
myChannel.stop();
}
play_btn1.addEventListener(MouseEvent.CLICK, onClickPlay);
function onClickPlay(e:MouseEvent):void
{
myChannel = mySound.play(lastPosition);
}
I am trying to make a restart button however everything I have read is not correctly working on bringing it back to the start of the sound. I am not really great with flash so I made it as simple as I could. Any and all help would be great.
Your code is fine and that's the correct way to implement a pause/play method in as3.
That means the problem is elsewhere. Print lastPosition at the start of your onClickPlay function. Is it printing something other than 0?
Take this as a comment. This thing only lets me post answers.
I'm creating Flash "memory" game, Idea to discover 2 equal cards, but I have 1 problem.
When I discover second card program write: "Wrong turn" and It is shown for 1 second, but at this time I can discover other cards, 3rd, 4th etc. I need to add something like "AllowClick = false" function, till 2 cards are shown.
As I understand I need to use this:
...RemoveEventListener(MouseEvent.CLICK, checkCards); Could you help me to use It correct?
DEMO
Here is part of my code:
else
{
trace("Wrong");
_message = "Wrong";
message_txt.text = _message;
_secondCard = event.currentTarget;
var timer:Timer = new Timer(1000, 1); //antros kortos atsivertimo laikas
timer.addEventListener(TimerEvent.TIMER_COMPLETE, flipBack);
timer.start();
}
}
protected function flipBack(event:TimerEvent):void
{
_firstCard.gotoAndPlay("flipBack");
_firstCard.addEventListener(MouseEvent.CLICK, checkCards);
_firstCard = _secondCard = undefined;
}
I hope you understood my question. Could you help me, please? Thank you very much.
Did you tried to set .mouseEnabled to false and .mouseChildren to false to all other elements? See here: as3 mouseEnabled still a problem for me
I have several tracks of audio that are in sinc. I would like to have one "TitleMusic" ON from the start, And allow the user to toggle ON and off the other tracks. My code As it stands has the "TitleMusic" playing from the start with all the other tracks playing too. I need to switch "track8" and all the other tracks (not showing) around so they are off at the start.This took me a long time to get to this point, I just need some help turning it around. Thanks
import flash.media.Sound;
import flash.media.SoundChannel;
var soundOn:Boolean = true;//This music is ON when we start
var myMusic:TitleMusic = new TitleMusic();
var myChannel1:SoundChannel = myMusic.play(0,1000);//endless loop, in effect
var soundOn3:Boolean = true; //music is ON when we start
var myMusic3:track8 = new track8();
var myChannel3:SoundChannel = myMusic3.play(0,1000); // endless loop, in effect
var myTransform3:SoundTransform;
mySoundButton3.addEventListener(MouseEvent.CLICK,toggleSound3);
mySoundButton3.buttonMode = true;
mySoundButton3.mouseChildren = false;
function toggleSound3(e:MouseEvent)
{
if(soundOn3)
{
// turn sound off
myTransform3 = new SoundTransform();
myTransform3.volume = 0; // silent
myChannel3.soundTransform = myTransform3;
soundOn3 = false;
mySoundButton3.myButtonText.text = "click to turn sound ON";
}
else // sound is off
{
// turn sound on
myTransform3 = new SoundTransform();
myTransform3.volume = 1; // full volume
myChannel3.soundTransform = myTransform3;
soundOn3 = true;
mySoundButton3.myButtonText.text = "click to turn sound OFF";
}
}
Couldn't you just put this line right after mySoundButton3.mouseChildren = false;:
toggleSound3(null);
Or, to be more efficient with memory, you could do this:
Take this line:
var myChannel3:SoundChannel = myMusic3.play(0,1000);
and change it to:
var myChannel3:SoundChannel;
This makes it so you're not actually starting the sound right away, but just creating the pointer for it (var)
Then, in your turn on block right after // turn sound on:
if(!myChannel13){
myChannel3 = myMusic3.play(0,1000);
}
This checks to see if you've started the sound yet, if not, it creates/starts the sound
You'll also want to change this line in your sound off block:
myChannel3.soundTransform = myTransform3;
to this
if(myChannel13){
myChannel3.soundTransform = myTransform3;
}
That way, if the off button is clicked before the on button, it won't throw an error.
I have 4 buttons on stage and I need a code that enables me to click on one of them, loop a specific sound "infinitely", and when it is clicked again, the sound stops. The sound is not initially playing. Also, while one of the sounds is looping, if I press another button, I'd like the previous sound to stop and the new one to play.
To help visualize this more, I will explain my project. I have to create an 'app' that is like an online guitar tuner. This feature is sort of what I would like to recreate:
http://www.gieson.com/Library/projects/utilities/tuner/
I don't even know where to begin with the coding... any help is greatly appreciated. Thank you!
The actual code is quite dependent on how you are loading in the sound, so I will write the "skeleton" for the code.
var currentSound:Sound = null;
var currentSoundChannel:SoundChannel;
var sound1:Sound = /* Load me */
var sound2:Sound = /* Load me */
button1.addEventListener(MouseEvent.CLICK, playSound1);
function playSound1(event:MouseEvent)
{
playSound(sound1);
}
button2.addEventListener(MouseEvent.CLICK, playSound2);
function playSound2(event:MouseEvent)
{
playSound(sound2);
}
function playSound(sound:Sound):void
{
if (currentSound != null)
{
// Stop the current music
currentSoundChannel.stop();
}
if (currentSound == sound)
{
// Stop playing ANY sound
currentSound = null;
currentSoundChannel = null;
}
else
{
// Play a different sound
currentSound = sound;
currentSoundChannel = sound.play();
}
}