Groups | Blog | Home
all groups > flash actionscript > november 2006 >

flash actionscript : How to play sound only on homepage?


mbeedub1
11/14/2006 11:48:10 PM
I'm a newbie so apologies if this is not the appropriate place for this post.

I have a flash animation that is used for navigation. I'm adapting the
animation. It is used to create the left navigation on each page. One of the
layers is a sound file. this is fine but plays when ever the user goes a new
page which is actually annoying.

I want to keep the sound playing when the home page loads (/index.asp) but
want to disable this when the page is anything other than /index.asp.

Is this possible in action script? Can you give me examples of the code and
where and how I would implement this.

As I say, I'm a newbie to flash so any help very gratefully appreciated.

Cheers

M
kglad
11/15/2006 2:58:20 AM
right click on your sound in your library, click linkage, tick export for
actionscript and assign a linkage id (say soundID). you can then use:



yourSound=new Sound(this);
yourSound.attachSound("soundID");
yourSound.start(); // <-- execute when you want your sound to start
// yourSound.stop(); // <-- execute when you want your sound to stop
mbeedub1
11/15/2006 5:13:02 PM
Thanks kglad

I've done that but it's not really clear to me how I test the name of the file
(i.e. /index.asp) and where I should put the code to do that.

As I say, I really am very new to this.

Cheers
kglad
11/15/2006 6:59:34 PM
attach the first two lines to frame 1 of your swf.

attach the 3rd line whereever you want your sound to start. that may be right
after the first 2 lines if you want the sound to start when your swf starts.

attach the 4th line (without comment indicator //) where you want your sound
to stop. that may be attached to a button that directs the user to a new page.
mbeedub1
11/15/2006 11:23:12 PM
Hi Again

Thanks for that. The thing is that this swf is used on everypage as the left
navigation. I do want the sound to play when the page loads but I only want it
to play for the home page of the site (i.e index.asp) and I don't know how to
test or query what page I'm on using action script.
kglad
11/16/2006 6:40:33 AM
mbeedub1
11/17/2006 3:15:35 PM
kglad
11/17/2006 3:26:13 PM
try:



if(this._url.indexOf("index")>-1){
yourSound=new Sound(this);
yourSound.attachSound("soundID");
yourSound.start();
mbeedub1
11/17/2006 5:01:16 PM
No that didn't seem to work.

It is possible to get a popup to appear when the final swf runs in the page to
tell me what the value of this._url is.

I tried Alert.show(this._url) but that didn't work.

Any other suggestions gratefully recieved.
kglad
11/18/2006 1:38:39 AM
for debugging purposes place a dynamic textfield (with instance name tf)
on-stage in you navigation swf.

in frame 1 of you navigation swf attach



tf.text=this._url;

// what appears in the text field when you navigate to the various pages?
AddThis Social Bookmark Button