A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Create movieclip on pressing spacebar (.fla inside)

  1. #1
    Senior Member
    Join Date
    Jul 2003
    Posts
    119

    Create movieclip on pressing spacebar (.fla inside)

    Here's my situation: I have a flash with a guy that can move left and right (Movieclip name: hero)
    In the library i have a movieclip of a fireball shooting upwards (fireball)

    This is the effect im trying to accomplish in essence: Whenever you push spacebar a movieclip is created (fireball) in the same position Another movieclip is currently in (hero). The ways i've managed it the fireball keeps following the hero left and right after it's created. But the idea is that once the Movie clip is created it'll be completely independant of the hero.

    Oh, and im looking for a possibility of this only being possible every 2 or 3ish seconds (as not to be able to spam fireballs)

    I've included the current .fla that i have with all the stuff in it. If anyone could help me out it would be very appriciated! Using Flash8

    Thanks!
    Attached Files Attached Files

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Hi, I opened your Flash file, but I did not see any coding for the fireball firing So I made my own 8D!

    Replace your code with this:

    PHP Code:
    onClipEvent(load) {
        
    speed 6;
        
    0;
        
    firing false;
        
        
    startFiring = function(){
            
    firing false;
        }
    }

    onClipEvent (enterFrame) {
        
    _y;
        
    _x;
        if (
    Key.isDown(Key.LEFT)) {
            
    -= speed;
        } else if (
    Key.isDown(Key.RIGHT)) {
            
    += speed;
        }
        
        if(
    Key.isDown(Key.SPACE) && firing == false) {
            
    _root.attachMovie("fireball""fireball"+ii, {_xx_yy});
            
    firing true;
            
    setTimeout(startFiring1000); // 1000ms = 1 second freeze
            
    i++;
        }
        
        if (
    _root.hit.hitTest(xytrue)) {
        } else {
            
    _x x;
            
    _y y;
        }
        if (
    _root.hit.hitTest(xytrue)) {
        }

    then give your Fireball movieclip a Linkage name of fireball -- and lastly, on the last frame of your Fireball movieclip, type this code on the Frame:

    Code:
    removeMovieClip(this);
    I'm sorry that I haven't really explained any of my modifications to the code -- it's just that there's a lot to explain if I did it, but if you really want an explanation, just say so and I'll try my best to make the code understandable
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Senior Member
    Join Date
    Jul 2003
    Posts
    119
    That did it! Works great, thanks alot!

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