# Problem with sound

**URL:** <https://forum.kirupa.com/t/problem-with-sound/183262>\
**Category:** Uncategorized\
**Created:** [March 25, 2006, 5:50am UTC](https://forum.kirupa.com/t/problem-with-sound/183262 "2006-03-25T05:50:41Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mictlantecuhtli](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@Mictlantecuhtli](https://forum.kirupa.com/u/Mictlantecuhtli)\
**Post date:** [March 25, 2006, 5:50am UTC](https://forum.kirupa.com/t/problem-with-sound/183262/1 "2006-03-25T05:50:41Z")

</div>

Hi there, I have a little problem with an animation in my web site, this animation have a little bell sound whe starts, My problem is that I want that soun to play only one time when people visit the website and stop to play in the meanwhile the people visit the other sections.

this is the code I haved been using:

```auto

intro_sound = new Sound (); 
intro_sound.attachSound("my_sound"); 

var played_so = SharedObject.getLocal("played"); 

if (played_so.data.played) 
{ 
   intro_sound.stop(); 
} else { 
   intro_sound.start(0, 1); 
} 
intro_sound.flush();

```

I’am a newbie with actionscript so please help me with this 😏

Greetings from Mexico

Mictlantecuhtli 😃

---

<div class="post-metadata">

**Author:** ![Mictlantecuhtli](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@Mictlantecuhtli](https://forum.kirupa.com/u/Mictlantecuhtli)\
**Post date:** [March 26, 2006, 6:49pm UTC](https://forum.kirupa.com/t/problem-with-sound/183262/2 "2006-03-26T18:49:58Z")

</div>

Anyone, please I need some help 😃

---

<div class="post-metadata">

**Author:** ![vintage](https://avatars.discourse-cdn.com/v4/letter/v/e68b1a/32.png) [@vintage](https://forum.kirupa.com/u/vintage)\
**Post date:** [March 26, 2006, 7:10pm UTC](https://forum.kirupa.com/t/problem-with-sound/183262/3 "2006-03-26T19:10:41Z")

</div>

Put this in youre timeline

```auto

played_so = SharedObject.getLocal("played", "/");
onLoad = function () {
    if (played_so.data.myValue != "played") {
        intro_sound.start(0, 1);
        played_so.data.myValue = "played";
        intro_sound.flush();
        intro_sound = new Sound();
        intro_sound.attachSound("my_sound");
        intro_sound.start();
    }
};

```

---

<div class="post-metadata">

**Author:** ![Mictlantecuhtli](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@Mictlantecuhtli](https://forum.kirupa.com/u/Mictlantecuhtli)\
**Post date:** [March 26, 2006, 7:36pm UTC](https://forum.kirupa.com/t/problem-with-sound/183262/4 "2006-03-26T19:36:07Z")

</div>

> [@vintage](#):
>
> Put this in youre timeline
> 
> ```auto
> 
> played_so = SharedObject.getLocal("played", "/");
> onLoad = function () {
> if (played_so.data.myValue != "played") {
> intro_sound.start(0, 1);
> played_so.data.myValue = "played";
> intro_sound.flush();
> intro_sound = new Sound();
> intro_sound.attachSound("my_sound");
> intro_sound.start();
> }
> };
> 
> ```

Man thank’s for your quick answer, you are the best :hugegrin:

Greetings from México

Mictlantecuhtli :evil:

---

<div class="post-metadata">

**Author:** ![vintage](https://avatars.discourse-cdn.com/v4/letter/v/e68b1a/32.png) [@vintage](https://forum.kirupa.com/u/vintage)\
**Post date:** [March 26, 2006, 8:16pm UTC](https://forum.kirupa.com/t/problem-with-sound/183262/5 "2006-03-26T20:16:35Z")

</div>

oh, I see I made a mistake, it shouldnt be intro\_sound.flush, but played\_so.flush, sorry 😛

Now for the question you asked via pm,  
I dont know a way to delete the shared object by “leaving” youre page…  
What i once did was put the date into the SO, and compared that with the date it is…so it plays only once a day.

Maybe you can use that, but if someone else knows a way to delete SO on leaving, than Im curious too on how to do that 😛

---

<div class="post-metadata">

**Author:** ![Mictlantecuhtli](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@Mictlantecuhtli](https://forum.kirupa.com/u/Mictlantecuhtli)\
**Post date:** [March 26, 2006, 8:27pm UTC](https://forum.kirupa.com/t/problem-with-sound/183262/6 "2006-03-26T20:27:55Z")

</div>

> [@vintage](#):
>
> oh, I see I made a mistake, it shouldnt be intro\_sound.flush, but played\_so.flush, sorry 😛
> 
> Now for the question you asked via pm,  
> I dont know a way to delete the shared object by “leaving” youre page…  
> What i once did was put the date into the SO, and compared that with the date it is…so it plays only once a day.
> 
> Maybe you can use that, but if someone else knows a way to delete SO on leaving, than Im curious too on how to do that 😛

Don’t worry the code works, and thank’s for everything

I’ll looking for an answer to delete or clear the content in the SharedObject if I find something usefull I’ll send you a pm :thumb2:

Sorry for my bad english :azn:

---

<div class="post-metadata">

**Author:** ![Mictlantecuhtli](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@Mictlantecuhtli](https://forum.kirupa.com/u/Mictlantecuhtli)\
**Post date:** [March 26, 2006, 8:34pm UTC](https://forum.kirupa.com/t/problem-with-sound/183262/7 "2006-03-26T20:34:33Z")

</div>

Here [SharedObject.clear();](http://livedocs.macromedia.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flash_MX_2004&file=00001664.html) say something about clear the content in the SO, but I don’t know if we could use that 😏

---

<div class="post-metadata">

**Author:** ![vintage](https://avatars.discourse-cdn.com/v4/letter/v/e68b1a/32.png) [@vintage](https://forum.kirupa.com/u/vintage)\
**Post date:** [March 26, 2006, 8:36pm UTC](https://forum.kirupa.com/t/problem-with-sound/183262/8 "2006-03-26T20:36:34Z")

</div>

I THINK I have an idea…gimme a little time and ill post it

---

<div class="post-metadata">

**Author:** ![Mictlantecuhtli](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@Mictlantecuhtli](https://forum.kirupa.com/u/Mictlantecuhtli)\
**Post date:** [March 26, 2006, 8:47pm UTC](https://forum.kirupa.com/t/problem-with-sound/183262/9 "2006-03-26T20:47:41Z")

</div>

> [@vintage](#):
>
> I THINK I have an idea…gimme a little time and ill post it

OK thank’s :thumb:

---

<div class="post-metadata">

**Author:** ![vintage](https://avatars.discourse-cdn.com/v4/letter/v/e68b1a/32.png) [@vintage](https://forum.kirupa.com/u/vintage)\
**Post date:** [March 26, 2006, 9:36pm UTC](https://forum.kirupa.com/t/problem-with-sound/183262/10 "2006-03-26T21:36:06Z")

</div>

I need some more info about the way you have youre site build.

Is that thing were talking about a header or smth simular ?  
And that header is included on different html pages ?

If yes, than i think i have a solution, you can change the SO on the index page via flashVars (so this will only work if people enters on the index page (not if they bookmarked smth else and enter there)(and even that is possible if you work with js history i guess)but its better than nothing, cuzz most people will enter the index.

If you use different pages with this swf header, all you have to do is put a flashVar on the index that will change the SO

for example this in the index.html  
\<param name=FlashVars VALUE="&played=no"\>

And in the onload function you pass that value to the SO  
On the “other” pages you dont put this flashVar

So if you enter the index, it will play, if you enter “sub” pages it wont…  
I think it would be more easy if you have php, this way you can use sessions, sessions are gone if browser is closed, so 2X more “luck”

I can make a verry long story out of this, but basicly I dont think there is an “onClose” thingy, and to make my idea work i need more info, and it wont be a solution for everyone, but only for youre site structure.

hopefully you understand what i say beqausse my english sucks as well 🙂

\*\*bigFat edit: \*\*if you have php, you can check on the $\_SERVER[‘HTTP\_REFERER’] and than change the flashVar…that would be easy 🙂

---

<div class="post-metadata">

**Author:** ![Mictlantecuhtli](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@Mictlantecuhtli](https://forum.kirupa.com/u/Mictlantecuhtli)\
**Post date:** [March 26, 2006, 10:21pm UTC](https://forum.kirupa.com/t/problem-with-sound/183262/11 "2006-03-26T22:21:01Z")

</div>

The site was build usin Mambo CMS which use PHP and MySQL

Maybe if you see the site you could have a better idea of what we need.

[www.dondecomemos.com](http://www.dondecomemos.com) the animation with the sound is the one that is at the left just below the header

Thank’s in advanced :thumb2:

---

<div class="post-metadata">

**Author:** ![vintage](https://avatars.discourse-cdn.com/v4/letter/v/e68b1a/32.png) [@vintage](https://forum.kirupa.com/u/vintage)\
**Post date:** [March 26, 2006, 10:27pm UTC](https://forum.kirupa.com/t/problem-with-sound/183262/12 "2006-03-26T22:27:49Z")

</div>

not that i understand anything from that language, but i think the thingy on the left side of the logo in the header plays the sound ?

And youre working with a \<?php include(“blaat.php”) ?\> sytem…hmmm  
Now its late her, but tomorrow im gonna look at it, i think its possible to fix it like i said, now im of to my bottle of whiskey 😛

Cya 2morrow here (or not) ill post my experiences here. gn8

---

<div class="post-metadata">

**Author:** ![Mictlantecuhtli](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@Mictlantecuhtli](https://forum.kirupa.com/u/Mictlantecuhtli)\
**Post date:** [March 26, 2006, 10:50pm UTC](https://forum.kirupa.com/t/problem-with-sound/183262/13 "2006-03-26T22:50:23Z")

</div>

> [@vintage](#):
>
> not that i understand anything from that language, but i think the thingy on the left side of the logo in the header plays the sound ?
> 
> And youre working with a \<?php include(“blaat.php”) ?\> sytem…hmmm  
> Now its late her, but tomorrow im gonna look at it, i think its possible to fix it like i said, now im of to my bottle of whiskey 😛
> 
> Cya 2morrow here (or not) ill post my experiences here. gn8

Okidoki thank’s man and cheers 🍺

---

<div class="post-metadata">

**Author:** ![vintage](https://avatars.discourse-cdn.com/v4/letter/v/e68b1a/32.png) [@vintage](https://forum.kirupa.com/u/vintage)\
**Post date:** [March 27, 2006, 8:52am UTC](https://forum.kirupa.com/t/problem-with-sound/183262/14 "2006-03-27T08:52:48Z")

</div>

Hmmzz, Im not having any luck…I can make flash detect if it have to play or not as you can see [here](http://vintagesworld.be/zooi/play1time/)

But…for some strange reason (I dont know why) It doenst work if I want to fix it in the onLoad = function(){}  
It works with an onEnterFrame function…but than te sound KEEPS playing  
So if anyone knows why it doenst work in the onLoad…pls tell 😉

As for the index Ive used this:

```php
<?php
error_reporting(E_ALL);
if(strpos($_SERVER['HTTP_REFERER'],"vintagesworld.be") >1)
	{
		$played = "yes";
	}
	else
	{
		$played = "no";
	}
?>

<object type="application/x-shockwave-flash" 
data="testing.swf" 
width="400" 
height="120">
<param name="movie" value="testing.swf" />
<param name=FlashVars VALUE="info=<?=$played?>">
</object>

```

And in flash ive used

```auto

onEnterFrame = function () {
	if (info != "yes") {
		//intro_sound = new Sound();
		//intro_sound.attachSound("my_sound");
		//intro_sound.start();
		test.text = "youve NOT seen this page before, so I have to play a sound";
	} else {
		test.text = "yes youre browsing on my site, so I DONT have to play a sound";
	}
};

```

Ive commented out the sound stuff, beqausse it keeps playing, but in an onLoad it doesnt work (for me), maybe I did something weird.

Anyway, if you can manage to do this in an onload, than you dont need SO at all.

gl

---

<div class="post-metadata">

**Author:** ![Mictlantecuhtli](https://avatars.discourse-cdn.com/v4/letter/m/779978/32.png) [@Mictlantecuhtli](https://forum.kirupa.com/u/Mictlantecuhtli)\
**Post date:** [March 28, 2006, 1:47pm UTC](https://forum.kirupa.com/t/problem-with-sound/183262/15 "2006-03-28T13:47:30Z")

</div>

Sorry about my delay to answer, but yesterday was Monday and I had to go to work :beard: Thank’s for all your help and I hope we can find and answer to this problem 😃

See you later 🍺

Mictlantecuhtli :evil:
