PDA

View Full Version : A Frustrated New User with some ?s


shaoSTYL3
07-22-2003, 02:40 AM
I started using Flash MX about 2 or 3 days ago.

I went through all the 'lessons' and have a good grasp of how to navigate with the program's GUI. After completing the puzzle piece tutorial, I decided to make a script of my own. I planned a simple script, just one with an animation in the background with music playing and a button that would start and stop said music. It turns out this simple sounding script is too much for me :(

here's what i wrote... the script for frame1
status = true;
sound.attachSound(tranzy);
_root.tranzy.start
if (status=true) {
msg = "Stop Music";
} else {msg = "Start Music";
}

the script for my sole button
on (release) {
if (status=true) {tranzy.stop();
} else {
tranzy.start();
status = false;
}
}

i'll try explaining what i was thinking if this looks like crap to all of you experts :D

the variable msg is for a dynamic text box that is on top of the button (so that it says either stop music or start music). status is a boolean for whether or not the music is playing. In my library, i have a wav that i named tranzy (in the linkage as well as in library), which is why i tried "_root.tranzy.start" (to play it from the very beginning).
Now as for the button's scripting... it should be pretty self-explanatory. Assuming that the music is already playing when the program starts (which it doesn't), clicking the button would turn it off if status were true and turn it off if status were false. That's what i planned for it to do, but it doesn't do anything at all.

Can someone help me at all? If you don't feel like taking the time to explain, could anyone at least upload a sample .fla with a button that starts/stops sound that i could look at?

lastly, if you need anymore information about my .fla that could help you help me, let me know.

Thanks...

patmanwb
07-22-2003, 03:00 AM
shaeSTYL3,

I will do my best to show you a sound and an event handler that starts the sound...


var tranzy = new Sound();
tranzy.attachSound("tranzy.mp3");


Do the above code in a new layer called 'sounds' in the first frame.

Then with the sound in the Library you need to set up the linkage propterty. So find your sound in the library and if it is not there you need to get it into the library :). Right click it and go to linkage, then click the "Export for ActionScript" check box and close the window.

Then on the button this code should work...

on (release){
if (playing){
_root.tranzy.stop();
playing = false;
}else{
_root.tranzy.start();
playing = true;
}
}

shaoSTYL3
07-22-2003, 02:17 PM
Thank you very much for your help! after using some of your code, I got my button to alternate between turning on and off the sound! Afterwards, I spent some time trying to get the text box to display the correct text (i think my trouble was that i put the variable setting code in the layer 1 instead of the button), and i got that too!

again... thanks ;)

senocular
07-22-2003, 02:28 PM
just a little something quick about if statements...

before you had

if (status=true)

^ that uses the = sign or the assignment operator in the parenthesis. = sets a value to equal another value, like when you originally assigned status to be equal to true. Now, if you want to compare two values to see if they are equivalent, like for instance if you want to see if status is the same as true, then you use the equality operator which is a double equals or == ...

if (status == true)

What patmanwb did was just have a playing variable in the if statement. The if statement just checks if that value alone can be evaluated into true or false and then uses that as the if condition. If the playing variable is equal to true, then if (playing) will evaluate to if (true) which will run the if statements that follow.

If you wanted to see if the playing variable was false, you could check it for false

if (playing == false)

or you could use

if (playing != true)

which is saying if playing is not equal to true - ! being the 'not' symbol. It can also be used like so

if (!playing)

This says if not playing then... statements. What !, or not, does, is revereses an evaluated true or false value. So !true is false.

etc.

patmanwb
07-22-2003, 02:35 PM
Thanks for doing the clean up senocular... I guess I should explain a bit more about what I am coding in my responses...


Thanks!

boyzdynasty
07-22-2003, 03:18 PM
I'm learning VB for my internship this summer and the stupid assignment and conditional statement ment the same thing *erRRR

Took me forever to fig. that out. :(

shaoSTYL3
07-22-2003, 04:14 PM
hm.m.. that might have been why my dynamic text box didnt' work earlier... thanks for the info.