A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: How to play a movie on button release?

  1. #1
    flash addict
    Join Date
    Jun 2003
    Posts
    136

    How to play a movie on button release?

    Hello,

    I have built a flash file with a number of buttons in it and I want to be able to press one of these buttons, and on the release, play a movie. eventually the other buttons will be doing the same thing(just playing different movies)

    to see an example of what I am talking about, you can check out www.puccaclub.com/eng
    ...and go to the amusement section where the flash movies are.

    I bet this is real simple to do and I've guessed some script but I keep getting errors.

    Thanks very much in advance. Anyone who could help will be much appreciated.
    ~"Flash is soooooooooooo flashy!"

  2. #2
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    hi..
    first...your "movieClip needs to have an instanceName (so FLASH can talk to it properly)

    so for this example..we'll use movieClip_1 which is just a 20 frame long animation of a ball goign round -n- round... ok?

    on yoru button you need to:
    a.) given an event that triggers you action
    b.) a target that you want to affect
    c.) the action you want performed.

    so similar to this:
    code:

    on(press) {
    movieClip_1.gotoAndPlay(2);
    }



    means start your movieClip_1 to start playing at frame# 2

  3. #3
    flash addict
    Join Date
    Jun 2003
    Posts
    136
    Thank you very much, however, I tried using that script and giving instance name to my movie and it's still a no go. By the way, I am using Flash MX Professional 2004...don't know if that makes a difference...

    I think a flash file that I could look at with how to do it would be very helpful...if that's not possible though, could you or anyone else offer some more step by step explanation? Thanks so much~~
    ~"Flash is soooooooooooo flashy!"

  4. #4

  5. #5
    Member
    Join Date
    Nov 2005
    Posts
    86
    you have your main file (where all the buttons are), have a layer in your main, call it "buttons", put your buttons here. add a new layer, call it "AS (fyi: actionscript)" this will be where we store our actionscript.

    add an instance name to each button (ex. btn1, btn2, btn3, etc. IN respective order).

    have your movie (other swf files) in the same directory as this main swf file. remember their names.

    now say our other swf files are the following
    -page1.swf
    -page2.swf
    -page3.swf

    and our buttons are the following (these are their instance names)
    -btn1
    -btn2
    -btn3

    WARP UP:
    BTN: 1, 2, and 3 are all in the layer "buttons". and the swf files: page1, page2, and page3 are all in the same directory as the main swf file.

    Now add the actionscript in the "AS" layer of the main file.

    btn1.onRelease = function(){
    loadMovie('page1.swf', 'myTargetMC');
    };

    btn2.onRelease = function(){
    loadMovie('page2.swf', 'myTargetMC');
    };

    btn3.onRelease = function(){
    loadMovie('page3.swf', 'myTargetMC');
    };
    Now create a target for the loading swf files, give it the instance name "myTargetMC"
    IT MUST BE THE SAME SIZE AS THE LOADING SWF FILES. Put myTargetMC on the main file "Stage 1".
    TurquoiseGala.org
    x-Sellus Shopping
    NYOC.net

  6. #6
    flash addict
    Join Date
    Jun 2003
    Posts
    136
    thank you alco and whispers.

    Alco, my questions now are...what do you mean by the buttons and page1.swf, etc. have to be in the same directory? and how do I create a target? where does it go in my main file?
    ~"Flash is soooooooooooo flashy!"

  7. #7
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    not sure what buttons in the directory mean....but if you want to load external.swf's into yoru MAIN.swf (and have them play on top or in certain sections) these .swf's need to be in the same directory as the MAIN.swf (for his code) but you can change the path to anywhere....

    a "target" is just a movieClip INSTANCE name...

    say I create new symbol.. (movieClip) I call it _blank.. I hit "OK"..
    in my library...I have a movieClip called "_blank" drag one of these movieClips to the stage...and place it anywhere... select it...and give it the INSTANCE NAME of "containerClip".

    containerClip is now your TARGET..so you cna now load things into ..

    code:

    on(press) {
    containerClip.loadMovie("external.swf");
    }




    it will now load that .swf into your MAIN movie..

    same with IMAGES...just replace external.swf to someImage.jpg

  8. #8
    flash addict
    Join Date
    Jun 2003
    Posts
    136
    Thank you very much for your brief response whispers...

    it worked. I didn't even bother deleting that actionscript alco told me about with the target mc and it still works with your code from the last post on the button.
    (before that, I eventually did get alco's method to work as well when you explained the directory stuff to me.)

    Now I have one more question...is there any way for me to get the movie ("page1.swf") to load on a specific position on the stage. right now it's just loading near the bottom of the stage, out of place, and I don't want it there.
    I want all the movies to eventually be loading in the same position, like they have them in that link I posted in my first post. puccaclub.com/eng
    Thanks-
    ~"Flash is soooooooooooo flashy!"

  9. #9
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    it will load where you place your TARGET clip....you can also create a movieClip (to be a container for this situation) on the fly...and position it.. (meaning you dont have the place the containerClip on the stage before hand)

    like so:
    code:

    this.createEmptyMovieClip("newClipName",getNextHig hestDepth());



    so you could do this:
    code:

    on(press) {
    this.createEmptyMovieClip("containerClip",getNextH ighestDepth());
    containerClip.loadMovie("external.swf");
    containerClip._x = 55;
    containerClip._y = 155;
    }


  10. #10
    flash addict
    Join Date
    Jun 2003
    Posts
    136
    okay but...if I position the page1.swf onstage beforehand let's say, people wills e it playing automatically won;t they??? I am so confused now.

    and what does that new piece of code mean? what do I replace the "this" and "createEMptymovieclip" with? sorry, but i should probably still be considered somewhat of a newbie because i need this stuff explained in steps. thanks for your patience~!
    ~"Flash is soooooooooooo flashy!"

  11. #11
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    you dont repleace createEmptyClip with anything..thats the actual command.

    this is like saying the "current" timeline..so you can use it anywhere (inside other clips even)

    peaople will see the .swf you load playing regardless... if you do NOT want them to see anything..put a stop(); action in the first frame of the EXTERNAL.swf

    and when you want to play...target it as such:

    _root.containerClip.play();

  12. #12
    flash addict
    Join Date
    Jun 2003
    Posts
    136
    Awesome~! thanks a bunch for your help...on my button, I put this code and it worked:

    on(press) {

    this.createEmptyMovieClip("containerClip",getNextH ighestDepth());

    containerClip.loadMovie("page1.swf");

    containerClip._x = 40;

    containerClip._y = 240;

    }


    So I just put that code on all of my buttons, just changing the external movie clip name of course, and it will continue to work? and so for example, if i press the button to play "page1.swf" and I watch it...and then I press the button to play "page2.swf", will "page1.swf" disappear so that you only see "page2.swf"? I might pm you in the future when those movies are actually completed...you don't have to answer now. Thanks again~~
    ~"Flash is soooooooooooo flashy!"

  13. #13
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    if you want to have it "replace" the content inside the "containerClip" you will need to change two things in this line:
    code:

    this.createEmptyMovieClip("containerClip",getNextH ighestDepth());




    1.) you will need to to "target" the same containerClip name (makes sense right?)
    and
    2.) you will need to NOT use this:
    code:

    getNextHighestDepth()


    as this will let you stack/layer the content on top of each other.

    actually if you keep the same target name..Im not sure you even need to change the depth paramater at all

  14. #14
    Member
    Join Date
    Nov 2005
    Posts
    86
    Okay... I've created a "demo" fla file with the swf files. In the folder attached is the: main.swf, main.fla, page1.swf, page1.fla, page2.swf, page2.fla. I have MX2004 so it may not work. But if it does take alook at what I did. I basically just created a MC (called it myTargetMC) made it the same dimensions as my pages that I want to load, and stuck it where i wanted my pages to load. I didn't want the myTargetMC to be visible so I added the code:

    myTargetMC._visible = false;
    And that closes the case on using: createEmptyMovieClip();

    That's all you have to do.

    And, mayy I suggest not to use buttons, use MC. And put all your code in one layer called Actions or AS, better organization. Just my thoughts, but do whatever you want. Take care.

    Alex
    Attached Files Attached Files
    Last edited by alco19357; 04-20-2006 at 10:40 PM. Reason: Forgot to add the zipped files.
    TurquoiseGala.org
    x-Sellus Shopping
    NYOC.net

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