Flash Advisor logo
:: Desktop Shortcut
:: Flash Help
Advice from Experts

+ Reply to Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Jun 2012
    Location
    Touring New England
    Posts
    10

    Default Sound Memory Question

    Hallo,

    In this AS2 example, there's two mp3 files with linkage names "annoying-mosquito" and "fly-swatter."

    I play the 1st mp3:

    SND = new Sound([_target]);
    SND.attachSound("annoying-mosquito");
    SND.start();

    Then I play the 2nd mp3:

    SND.attachSound("fly-swatter");
    SND.start();

    Both the 1st mp3 & the 2nd mp3 are attached to the same variable SND with (seemingly) no ill effect.

    Question: do I need to clear the contents of the variable SND before the 2nd attachSound?

    Or is Flash doing that for me?

    Thanks for your time.
    Last edited by seajay; 06-18-2012 at 06:57 AM. Reason: simplify

  2. # ADS
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many
     
  3. #2
    Join Date
    Jun 2009
    Location
    Houston, Tx
    Posts
    581

    Default

    I'm a little concerned about "B = delete snd;"
    What do you expect from setting B to this? Especially since B isn't anything.

    If you really want to know what is happening, then the best thing to do is read Flash help docs.
    Unfortunately, "attachSound" isn't a well documented function, as it part of Flash Lite 2.0 or something, not the standard AS3.

    I would suggest doing what Adobe would do.
    I'm considering that your sounds are inside the Flash library.
    http://help.adobe.com/en_US/as3/dev/...0204-7d24.html

    You will have to give your sound items a variable name to export for actionscript.
    Then you use the name. So let's say your mosquito sound is named sndMosquito or something.

    var sound:sndMosquito = new sndMosquito();
    var channel:SoundChannel = sound.play();

    Work around with this, since it is the more advanced way of doing what you want.
    Sound channels capture the sound you want to play and then can do things to it, or stop it if you need.

    Then you can probably reuse the same sound channel, or you don't have to. Up to you.

  4. #3
    Join Date
    Jun 2012
    Location
    Touring New England
    Posts
    10

    Default **** Boolean

    B = delete x;

    "The delete operator can fail and return false if the reference parameter does not exist or cannot be deleted."

    For me, this is useful information.

    Thanks for the Adobe link. I'll look into it.
    Last edited by seajay; 06-18-2012 at 06:59 AM. Reason: bad grammar

  5. #4
    Join Date
    Jun 2012
    Location
    Touring New England
    Posts
    10

    Default

    (Oops, the 4-letter adjective from my title was deleted. It wasn't a curse word, but a type of metal.)

    SND = new Sound([_target]);
    SND.attachSound("annoying-mosquito");
    SND.start();

    And later:

    SND.attachSound("fly-swatter");
    SND.start();

    I've concluded this AS2 code is safe.

    Flash loads the sound into memory and knows what to do with it.

    SND is only a pointer to that sound in memory and can be set to other sounds as needed.

    I appreciate the help.
    Last edited by seajay; 06-18-2012 at 12:22 PM. Reason: found answer

  6. #5
    Join Date
    Jun 2009
    Location
    Houston, Tx
    Posts
    581

    Default

    Of course it is safe. If Flash doesn't throw any exceptions, then you can assume anything is safe.

    But as far as if the memory allocation is ok, then you are correct.
    But that doesn't make it the most efficient or best way, which is all I was saying.

    Anyways. I was just wondering if you knew what you were doing with B. I try to instill good programming habits in anyone I help.
    SND and B are what I would call bad variable naming. So I wasn't sure if you put "B =" or if you took that code from someone else.

    I would personally stay away from attachSound and attachMovieClip. However, I work with AS3, so there are better choices.
    Other than that, good luck with your project.

  7. #6
    Join Date
    Jun 2012
    Location
    Touring New England
    Posts
    10

    Default

    Indeed. I'm certain AS3 is better.

    However I'm finishing an enormous project which started in AS2, and on my list of Things-To-Do, converting nearly a million of lines of code to AS3 will not be one of them.

    Bad programming habits? Stuff and nonsense.

    I use single letters for variables when they are local to a function and are used straight away and then are needed no longer... such as X, Y, Z, A, B, N, S... and I always use them to mean the exact same thing.

    B is for Boolean.
    Last edited by seajay; 06-18-2012 at 03:35 PM. Reason: grammar

  8. #7
    Join Date
    Jun 2009
    Location
    Houston, Tx
    Posts
    581

    Default

    I see. Well. No need trying to convert a million lines. I wouldn't want to go back through a project after working on it for years, either.
    But yes. Bad programming habits. It's real. And it's a real problem.
    However, if you use the same name for the same thing, then that is a reasonable way to go about it.
    It just happens that the usual poster on these forums are new to programming and flash.
    I don't think I've had someone ask a legit question who has coded more than maybe several hundred lines at a time, if that.

    I typically name all my variables with more than 4 letters. For a boolean, I would probably name it Boolean, haha. Or something like that.
    I find it rather difficult trying to find and replace anything less than that. I'm sure you know what I mean, though.

    Glad to hear you are almost done with your current project.
    God speed.

  9. #8
    Join Date
    Jun 2012
    Location
    Touring New England
    Posts
    10

    Default

    For me, variable names and function names are a fine art.

    When I bought my Mac 512K in late 1984, it was strictly for word processing and spread sheets. That next year, because I had monkeyed around with the BASIC cartridge for the Atari 2600 (that's not a typo), I thought it might be "fun" to try Basic for the Mac.

    Immediately, I discovered that "help" books and sample programs were completely unreadable (to me).

    FOR myInitializeTimingArray = 1 TO myTimingArrayTotal STEP myStepInitializeTimingArray

    myTimingArray[myInitializeTimingArray ] = myInitializeTimingArray

    NEXT

    That's when I began my crusade for immediately readable code.

    To me, anyway.

    LOCAL VARIABLES INSIDE FUNCTIONS for specific and temporary usage.

    --- Uppercase 1-letter - X, Y, Z for loops - B, N, S, A for Boolean, Number, String, Array

    --- Lowercase 2-letter - ct is my only one.

    --- Lowercase 3-5 letters - min, max, incre, my mind's a blank

    LAYER VARIABLES - those used throughout all the scripts belonging to the same layer.

    ROOT VARIABLES - those belonging to the "_root" layer of a given Flash.fla or Flash.as.

    Hold on. I'm writing a treatise here. I need to get back to work.

    Yikes!

  10. #9
    Join Date
    Jun 2009
    Location
    Houston, Tx
    Posts
    581

    Default

    Sounds like you have your style down.
    It's nice to find someone who has their own theory going.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Sponsors
Create Speaking Characters for your website and Flash movies. 15 Day Free Trial