A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Its been a while...

  1. #1
    The next Squaresoft
    Join Date
    Sep 2004
    Location
    Zanarkand
    Posts
    215

    Its been a while...

    hey dudes!

    its been a while!!! i havent been here in months!!

    anyway, my FF game is going greaT!!!
    (thanks to the people here in flashkit)

    umm but, i wanna ask something that will greatly help my game

    is it possible to make a duplicatemovieclip/create out of nowhere command that has all the things the original MC has?

    like actionscripts and instance name(or better yet, a specified instance name for the clone)

    yeah and, if it was possible, a command that detects if a certain MC was in the stage...

    umm wierd but it i relly need that, dont worryy, im experimenting scripts as i type....(is that possible!?)

    anyway, thanks a bunch dudes!!
    "Are those gummy worms? Can I have some?"

    "Nevermind, I just saw one move by itself..."

  2. #2
    Junior Senior
    Join Date
    Nov 2000
    Location
    sydney
    Posts
    565
    sort of...
    you can do this:
    Code:
    cloneMC = originalMC.duplicateMovieClip("cloneName", cloneDepth);
    cloneMC.onEnterFrame = function() {
      // code for clone, or call another function here
      // with(this){...} is often useful inside dynamically allocated functions like this.
    }
    for checking if an MC is visible on the stage... if you have a mask layer which covers all other layers to stop the swf spilling out over the stage edges, you could convert that mask layer to an MC. That way your other MCs can hitTest against it.
    Last edited by slight; 06-28-2005 at 05:25 AM. Reason: PS
    Signature

  3. #3
    The next Squaresoft
    Join Date
    Sep 2004
    Location
    Zanarkand
    Posts
    215
    hmm, you know, i never really got an exact idea of what
    the code function() is...

    is it like, a set of commands under function()

    and if that function is called, the scripts inside it are given to the one who called the function?

    im not sure, but thats my idea..can u explain to me a bit?

    and also, what do you mean by (this)(...)?

    anyway, thanks a bunch dude!!
    "Are those gummy worms? Can I have some?"

    "Nevermind, I just saw one move by itself..."

  4. #4
    The next Squaresoft
    Join Date
    Sep 2004
    Location
    Zanarkand
    Posts
    215
    sorry i forgot to add something

    umm, when the movie clip is duplicated, the name given to it in the command is also its instance name right?

    oh yeah, so if it is possible to duplicate a movie clip, is it possible to duplicate a button too?

    thanks again!
    "Are those gummy worms? Can I have some?"

    "Nevermind, I just saw one move by itself..."

  5. #5
    Junior Senior
    Join Date
    Nov 2000
    Location
    sydney
    Posts
    565
    last question first. In the line :

    cloneMC = originalMC.duplicateMovieClip("cloneName", cloneDepth);

    the instance name is "cloneName", while "cloneMC" is a reference to the instance. This referencing is not always needed. you can just create an instance like this:

    originalMC.duplicateMovieClip("cloneName", cloneDepth);
    cloneName._x = 100;

    but the first way is useful if you are making lots of instances with different names: eg:

    for (d=0; d<100; d++){
    NewMC = originalMC.duplicateMovieClip("cloneName" + d, d );
    NewMC._x = 100;
    }

    functions.. setting up an onEnterFrame function on the fly isnt exactly the standard way of using functions. there are many ways you can set up functions, a simple example...

    onClipEvent (load) {
    function moveleft() {
    _x -= 10;
    }
    }

    onClipEvent (enterFrame) {
    moveLeft();
    }

    but if your MC is called player, from anywhere in your flash, you can say:

    player.moveLeft();

    You can also make a function like this on the root timeline that would move any MC left:

    function moveLeft(target){
    target._x -=10;
    }


    from inside an MC, you pass the function a reference to the MC like this:

    _root.moveLeft(this);

    or you could pass a different MC to the function, and it will get moved. eg:

    _root.moveLeft(player);

    Now, the onEnterFrame example in my first post is a bit different, but to explain that, lets take another look at how we defined moveLeft.

    function moveleft(){...}

    can also be written as:

    moveleft = function(){...}

    or even

    cloneMC.moveLeft = function(){...}

    which is now starting to look a lot like our onEnterFrame definition:

    cloneMC.onEnterFrame = function() {...}

    except that onEnterFrame is obviously a special case that doesnt need to be called for it to run.

    That all looks like a lot to take in, but its just the tip of the iceberg for functions. they are extremely useful, and the way flash implements them is extremely flexible.

    oh, and the line:

    with(this){...

    saying

    player.moveLeft()
    player._y+=2;

    is the same as saying

    with(player){
    moveLeft();
    _y+=2;
    }

    but when you make a duplicate MC and assign it an onEnterFrame function, it can get a little ambiguous which MC's variables are referred to in that function, especially if there is child and parent MC's involved. putting the whole contents of the function inside a "with(this){...}" will usually make your enterframe behave as expected.
    Signature

  6. #6
    The next Squaresoft
    Join Date
    Sep 2004
    Location
    Zanarkand
    Posts
    215
    ohh sorry it look so long for me to reply...

    anyway, thanks a lot dude!!! now my rpg party system will
    go on as planned!!!

    thanx again!
    "Are those gummy worms? Can I have some?"

    "Nevermind, I just saw one move by itself..."

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