A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Sound won't play with this script naming.

  1. #1
    Heavyweight Pixel Champion Pixel Puncher's Avatar
    Join Date
    Oct 2002
    Location
    State of Confusion
    Posts
    485

    Sound won't play with this script naming.

    I am trying to get my sound to play when it is within a movie. Right now it won't play unless it is in it's own swf but as soon as I have to load this swf into an empty movie clip it no longer works. This is the code I have on my button which is inside of a movie that is loaded into a "master movie."
    Code:
    on (rollOver) {
        _root.emptyClip.mySound11 = new Sound();
        _root.emptyClip.mySound11.attachSound("Answer01-1.mp3");
        _root.emptyClip.mySound11.start()
    }
    on (rollOut) {
        _root.emptyClip.mySound11 = new Sound();
        _root.emptyClip.mySound11.attachSound("Answer01-1.mp3");
        _root.emptyClip.mySound11.stop()
    }
    So it works if I don't use "_root.emptyClip" and if I view it on it's own but I have to load this movie into another one so that is why I was trying it with this naming convention. Any thoughts why it wouldn't work on loading into another movie? Thanks
    If your friends with "P" well then your friends with me. If your down with "P" well then your down with me.

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    Two different problems:
    1) never use _root. It (may) will cause problems when loaded into a movie clip.
    2)use this when creating the sound (this or some other movie clip):
    code:

    emptyClip.mySound11 = new Sound(this);


    Obviously you don't need to create the same sound and attach the same music file twice:
    code:

    on (rollOver) {
    emptyClip.mySound11 = new Sound(this);
    emptyClip.mySound11.attachSound("Answer01-1.mp3");
    emptyClip.mySound11.start();
    }
    on (rollOut) {
    emptyClip.mySound11.stop();
    }


  3. #3
    Heavyweight Pixel Champion Pixel Puncher's Avatar
    Join Date
    Oct 2002
    Location
    State of Confusion
    Posts
    485
    How come "this" is used in this case? _root is usually used for everything. Is this only for sounds only? Anyhow, "this" method does work, thanks for the reply.
    If your friends with "P" well then your friends with me. If your down with "P" well then your down with me.

  4. #4
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    "when a movie with an exported sound is loaded into a target level or movie clip, the exported sound can be attached only if the sound object's specified target matches that level or clip"

    Colin Moock, Action Script for Flash MX, the Definitive Guide.

    "_root is usually used for everything."
    When you are still learning, that may be true, which doesn't mean it's a good practice. Simply don't use it. Use relative references instead (read understanding target paths).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center