Groups | Blog | Home
all groups > flash actionscript > july 2005 >

flash actionscript : shopping cart...kinda


livingwithanangel
7/11/2005 9:34:26 PM
I have a page of 20 sounds. I want someone to be able to select 2 of these
sounds. Once two are picked, I want the visitor to go to a new window and see
both the sounds, be able to play them or delete one (if one is deleted they
should go back to the main page to pick another sound) and also have the option
of playing both sounds together (one after the other).
Is this hard?
Can anyone show me how to do it?
I'm not well versed in actionscripting....
Many thanks in advance!

Jon Moyles
7/12/2005 12:00:00 AM
check out the Sound() function in the docs.

you'll want to embed your sounds in the movie, import them into the library, right click
them and select "linkage", deselect "export in first frame" and place them on the timeline
where they will be called, somewhere the playhead isnt going to go, ie. after the rest of
the movie.

heres a function that can play one sound after another:

function goSound(aSound, sound2, sound3){
trace("aSound = " + aSound);
trace("sound2 = " + sound2);
trace("sound3 = " + sound3);
theSound.stop();
theSound.attachSound(aSound);
theSound.start();
if(sound3){
theSound.onSoundComplete = function(){
goSound(sound2,sound3);
}
}else if(sound2){
theSound.onSoundComplete = function(){
goSound(sound2);
}
}else{
theSound.onSoundComplete = soundEnded;
}
}

note that to use this function you have to declare a Sound object called theSound like so:

theSound = new Sound();

it calls a function called soundEnded() when its done playing sounds but it will still work
if this function is not defined.


good luck
livingwithanangel
7/12/2005 12:35:45 PM
hi jon,
I did my best - please see the following and if you could let me know where I
went wrong, that would be great!
http://www.basement143.com/flash
for the initial sounds in http://www.basement143.com/flash/page1_sample.swf I
used the external mp3 link option which was the only option I could get to work.
for the second page sample, I'm afraid I couldn't get your code to work - I
know it's me, but am stumped...
thanks again!
Jon Moyles
7/18/2005 12:00:00 AM
hey
i looked at your movie (number 2)
you havent linked up the sounds from the "linkage" link in the library (see previous post)
you need to declare
theSound = new Sound();
just once, on a frame that gets played, like your main script frame (frame 1)

your "link and play" button needs to call the funtion goSound(), at the moment it decalres
the function. you call the function like so:

goSound("sound1.mp3", "sound2.mp3");

if you put that on your "link and play" button as is and link up the sounds with those names
it should make some noise.

and to get the result you want you will need to dynamically enter the strings for the sounds
(i'll go into that next time if you can get some sound playing)

luck
livingwithanangel
7/18/2005 12:00:33 PM
hi Jon,

I get these errors when I click on the "link and play" box when I test the
movie
aSound =undefined
sound2 = undifined
sound3=undefined

I've updated the "sound experiment 2.fla file in the same folder as beofer if
you get a chance to look and see what I'm missing! Thanks
Jon Moyles
7/19/2005 12:00:00 AM
ok, sorry, i've confused you

the function needs to be declared first (as written in my first post, on
the main timeline, in say frame 1)

then it needs to be called, the single line from my second post, placed
on, in this case, the button you want to perform the action.

also it wont work unless you link up the sound by right clicking and
selecting "linkage" then "export for actionscript" and deselect "export
in first frame"

livingwithanangel
8/3/2005 9:23:05 AM
hi Jon,
I have to get a small demo of this ready to show a potential client for
Tomorrow - is there any way you could get it done for then, I can send over a
payment to you via paypal or something for your time.

I have to have screen 1 with 40 buttons (each will eventually have it's own
sound, but for the demo, I only need 2 different sounds), and when you click on
a button, the sound plays, and you can also click on a "add to cart" button.
When 2 sounds have been added to the cart you go to screen 2 and see 2 buttons
- 2 correspond with the sounds you chose on screen 1 and will play these sounds
when clicked, and the third plays both sounds together, one after the other.

If you could do this, please let me know asap. lwaa@mac.com thanks so much.

I'm going to be taking a flash course soon, but have to have this demo ready
tomorrow to try to snag this new client - thanks again
AddThis Social Bookmark Button