Be a Supporter!

Calling sound & use of dynamic text

  • 358 Views
  • 7 Replies
New Topic Respond to this Topic
VegetarianMeat
VegetarianMeat
  • Member since: Jun. 5, 2004
  • Offline.
Forum Stats
Member
Level 18
Musician
Calling sound & use of dynamic text May. 23rd, 2010 @ 01:04 AM Reply

I have two questions, but I figured I'd keep them both in one post.

1st question:
I want to use Action Script to start a sound. I've looked around, but everything I see seems to be way too fancy for my level. I am a beginner, and pretty much know extremely little about how all this stuff works. I figure it would be a simple single line of code, but when I checked (I googled 'using sound in action script') I didn't find anything useful for me.

2nd question:
I have a string of dynamic text. I assigned it a name and on the first frame of the timeline I set that variable to equal a certain number. That's irrelevant, because it works fine. The variable I entered into the timeline works as it should. When I try and rotate the dynamic text though, so that it's not just plain horizontal, it seems to break it's function, and doesn't display the variable I assigned. I checked to make sure, and it still had the same variable name. Am I not able to rotate dynamic text without breaking the variable function?

Thanks in advance. You guys are always helpful here :)

VegetarianMeat
VegetarianMeat
  • Member since: Jun. 5, 2004
  • Offline.
Forum Stats
Member
Level 18
Musician
Response to Calling sound & use of dynamic text May. 23rd, 2010 @ 05:28 PM Reply

New issue: tried the game on a different PC - the font of the dynamic text is different from the one I used in the original flash. I'm guessing that's because I downloaded the font online somewhere so this computer doesn't have it. Besides telling whoever plays the game to download the font, is there any way around this problem?

Torrunt
Torrunt
  • Member since: May. 3, 2007
  • Offline.
Forum Stats
Member
Level 22
Programmer
Response to Calling sound & use of dynamic text May. 24th, 2010 @ 08:51 AM Reply

@ Q1: Depends on what AS version you're using.
First you add the sound you want to your library, right click it and give it a linkage name then -

AS2

var name = new Sound(this);
name.attachSound("linkagename");

and use this to call it:

name.start(0, 0);

AS3

var name:Sound = new linkagename();

and use this to call it:

name.play();

(Look in the Help files (F1) in flash on some of those functions to give you some more understanding on what you can do with them).

@ Q2: How exactly are you rotating it? I tried quickly myself (in AS2 and AS3) using the rotation variable and it worked fine.

@ Q3: You just have to embed the font into the swf. There should be an embed button in the properties window when you have the text box selected.


BBS Signature
VegetarianMeat
VegetarianMeat
  • Member since: Jun. 5, 2004
  • Offline.
Forum Stats
Member
Level 18
Musician
Response to Calling sound & use of dynamic text May. 24th, 2010 @ 10:45 PM Reply

At 5/24/10 08:51 AM, Torrunt wrote: @ Q1: Depends on what AS version you're using.
First you add the sound you want to your library, right click it and give it a linkage name then -

Currently I'm working with AS2 (Flash 8). That sound code worked perfectly, I'll check out the Flash Help stuff to have a deeper understanding of it. Thanks!

@ Q2: How exactly are you rotating it? I tried quickly myself (in AS2 and AS3) using the rotation variable and it worked fine.

I'm just using the free transform tool. I'm guessing the rotation variable concerns writing a code that tells it to rotate?

@ Q3: You just have to embed the font into the swf. There should be an embed button in the properties window when you have the text box selected.

That makes sense, however I just gave it a shot and when I tested it the text didn't show up. I tried selected different things from the font that it would embed (numericals, letters etc.).

In making my little test game, I came upon another problem that I haven't figured out how to solve just yet. I'm trying to create a code that tells the flash that when the space bar is pressed, a number (5) is added to another number. It seems I've succeeded in doing that, however if you hold it down, it just keeps on adding and adding. I'm trying to figure out so that you have to have released the space bar before it adds any more.

Thanks a lot for your help, I really appreciate it. Starting from scratch with no programming background is pretty difficult, but I enjoy learning about it and trying to figure stuff out (then eventually giving up and asking here :P !)

Torrunt
Torrunt
  • Member since: May. 3, 2007
  • Offline.
Forum Stats
Member
Level 22
Programmer
Response to Calling sound & use of dynamic text May. 25th, 2010 @ 03:42 AM Reply

At 5/24/10 10:45 PM, VegetarianMeat wrote: I'm just using the free transform tool. I'm guessing the rotation variable concerns writing a code that tells it to rotate?

Yeah, i thought you was rotating it with AS. I tried myself using the transform tool and it doesn't effect it but maybe that's because I'm using CS5. I wouldn't think rotating it would mess it up in any version of flash though, not sure what's going on there.

That makes sense, however I just gave it a shot and when I tested it the text didn't show up. I tried selected different things from the font that it would embed (numericals, letters etc.).

Not sure why it wouldn't work, I've never used Flash 8 so i'm not entirely sure what the interface is like. Try this tutorial which includes embedding fonts in Flash 8.

In making my little test game, I came upon another problem that I haven't figured out how to solve just yet. I'm trying to create a code that tells the flash that when the space bar is pressed, a number (5) is added to another number. It seems I've succeeded in doing that, however if you hold it down, it just keeps on adding and adding. I'm trying to figure out so that you have to have released the space bar before it adds any more.

I would just make a Boolean called spaceKeyDown or something and somewhere in your enterframe function (after the code checking the key press) just have something like:

spaceKeyDown = (Key.isDown(Key.SPACE));

(or however you check for key presses in AS2) and then just add:

&& !spaceKeyDown

at the end of your if statment. This will make it so it will only add 5 (or whatever you want to happen when you press space) once when you press space.


BBS Signature
VegetarianMeat
VegetarianMeat
  • Member since: Jun. 5, 2004
  • Offline.
Forum Stats
Member
Level 18
Musician
Response to Calling sound & use of dynamic text May. 26th, 2010 @ 02:20 AM Reply

At 5/25/10 03:42 AM, Torrunt wrote: I wouldn't think rotating it would mess it up in any version of flash though, not sure what's going on there.

It's not that big of an issue yet, I'm just practicing so I'll figure that out some other time.

Not sure why it wouldn't work, I've never used Flash 8 so i'm not entirely sure what the interface is like. Try this tutorial which includes embedding fonts in Flash 8.

Pretty sure I did it like that, in any case, I can also deal with that once I figure out my programming problems, heh.

I would just make a Boolean called spaceKeyDown or something and somewhere in your enterframe function (after the code checking the key press) just have something like:
...This will make it so it will only add 5 (or whatever you want to happen when you press space) once when you press space.

I was using the 'onKeyPress' function, but this seems like a much more efficient way to do it. I put in this code as a test just to see if it would work:

onClipEvent (enterFrame) {
spaceKeyDown = (Key.isDown(Key.SPACE));
if (spaceKeyDown) {
_root.number += 5
}
}

It worked as it had before, but the code does look much cleaner, so I'll be using that function much more now. Then I tried adding the other part creating:

_root.number += 5 && !spaceKeyDown

This seemed to break the code, with the number not changing at all when I press space. It seems like it would work though. From what I understand && = and, also ! = not. So it seems as though this would tell it that after 5 is added, the space key is not down. For some reason it doesn't work though.

Again, I really appreciate your help. Thanks again :)

Torrunt
Torrunt
  • Member since: May. 3, 2007
  • Offline.
Forum Stats
Member
Level 22
Programmer
Response to Calling sound & use of dynamic text May. 26th, 2010 @ 06:15 AM Reply

At 5/26/10 02:20 AM, VegetarianMeat wrote: _root.number += 5 && !spaceKeyDown

This seemed to break the code, with the number not changing at all when I press space. It seems like it would work though. From what I understand && = and, also ! = not. So it seems as though this would tell it that after 5 is added, the space key is not down. For some reason it doesn't work though.

You add the [&& !spaceKeyDown] in the if statement, like:

if (Key.isDown(Key.SPACE) && !spaceKeyDown) {
 _root.number += 5
}
spaceKeyDown = Key.isDown(Key.SPACE) ;

also have the spaceKeyDown boolean change after the if statement so the if statement can through at least once.

If you still don't really get why this works, i could try explaining it in more detail if you want.


BBS Signature
VegetarianMeat
VegetarianMeat
  • Member since: Jun. 5, 2004
  • Offline.
Forum Stats
Member
Level 18
Musician
Response to Calling sound & use of dynamic text May. 26th, 2010 @ 10:50 AM Reply

At 5/26/10 06:15 AM, Torrunt wrote: If you still don't really get why this works, i could try explaining it in more detail if you want.

If I understand correctly, it goes like this: first it checks for space being down, and then if the Boolean 'spaceKeyDown' is false it adds five. Since that boolean isn't set at first, it just passes it then adds the 5. Afterwords the boolean is set though, and so if the key is still down the loop stops.

Would I be right in assuming that's how it's working :P

It worked by the way, thanks a lot :D