A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Duplicate Movie problem. s

Hybrid View

  1. #1
    11 Years Old Boya
    Join Date
    Apr 2004
    Posts
    61

    Duplicate Movie problem. s

    How come when I tried to assign the x and y of a duplicated 'laser1' mc to the xy of the movie clip inside a movieclip, the xy of the laser mc is zero. (sorry for the bad english)

    The movie clip(cannonmc) that contains the script is inside another movie clip(cannon) followed by a 'ship' mc.

    This is the script of the 'cannonmc' mc.
    Code:
    onClipEvent(load) {
    	shots = 0;
    }
    onClipEvent(enterFrame) {
    	if(Key.isDown(Key.SPACE)) {
    		duplicateMovieClip(_root.laser1, "shootlas1"+shots, 7000+shots);
    		_root["shootlas1"+shots]._x = this._x+20;
    		_root["shootlas1"+shots]._y = this._y+10;
    		if(shots != 99) {
    			shots++;
    		} else { shots = 0; }
    	}
    }
    When 'ship' mc moves, the duplicated movie doesn't follow the moved 'cannon' mc.

    Please help me.
    Checkout my site:
    Click HERE
    Checkout my games:
    Oops! No game for now!

  2. #2
    Member Pepember
    Join Date
    Jul 2001
    Location
    Berlin
    Posts
    886
    try:
    var temp = duplicateMovieClip(_root.laser1, "shootlas1"+shots, 7000+shots);
    temp._x = this._x+20;
    temp._y = this._y+10;
    Please sign here

  3. #3
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    Watch out theTick !
    duplicateMovieClip(target,newname, depth) does not return the copied instance.. it's wrong in help...
    only MovieClip.duplicateMovieClip(newname,depth) does !!!
    (this has been corrected in Flash8 help / LiveDocs)


    [edit] from here i first wrote BS...
    @your problem:

    You just set the x/y position of the laser shot only once, on duplication...
    that's where it will stay.
    Last edited by McUsher; 11-25-2005 at 02:10 PM.
    My letters on the F1 key have faded, how are yours today?

  4. #4
    Member Pepember
    Join Date
    Jul 2001
    Location
    Berlin
    Posts
    886
    ah...thanks. that slipped my attention. i usually use the MovieClip method...
    Please sign here

  5. #5
    11 Years Old Boya
    Join Date
    Apr 2004
    Posts
    61
    Hmm...maybe showing me the code would help.
    Checkout my site:
    Click HERE
    Checkout my games:
    Oops! No game for now!

  6. #6
    Member Pepember
    Join Date
    Jul 2001
    Location
    Berlin
    Posts
    886
    PHP Code:
    duplicateMovieClip(_root.laser1"shootlas1"+shots7000+shots);
    _root["shootlas1"+shots].onEnterFrame = function ()
    {
      
    this._x +=20;
    }
    _root["shootlas1"+shots].onEnterFrame = function ()
    {
      
    this._y +=10;

    thus, you assign an onEnterFrame event to all newly created shots that continuously adds to its _x or _y position...although you might want to decrease the value you add...
    Please sign here

  7. #7
    11 Years Old Boya
    Join Date
    Apr 2004
    Posts
    61
    I wonder how do you get the xy of a movie clip(that is in another movie clip) on the stage...
    I tried tracing the xy of the 'cannonmc' mc and the result is 0...

    edit:
    'cannon' mc is actually attached into the 'ship' mc through actionscript. Could this be part of the problem?
    Last edited by Gamerflash; 11-25-2005 at 08:41 PM.
    Checkout my site:
    Click HERE
    Checkout my games:
    Oops! No game for now!

  8. #8
    11 Years Old Boya
    Join Date
    Apr 2004
    Posts
    61
    Please help me somebody!
    Checkout my site:
    Click HERE
    Checkout my games:
    Oops! No game for now!

  9. #9
    Member Pepember
    Join Date
    Jul 2001
    Location
    Berlin
    Posts
    886
    you can use the MovieClipMethod localToGlobal() to transform cannonmc's local coordinates (which will always be the same inside the ship mc, because i suppose you don't move the cannonmc around inside the ship mc) to stage coordinates.
    there's a good example how to correctly use the method in the help files.
    Last edited by theTick; 11-26-2005 at 06:49 AM.
    Please sign here

  10. #10
    Flash Gordon McUsher's Avatar
    Join Date
    Mar 2001
    Location
    Krautland
    Posts
    1,560
    Hmm.. i think it would be easier, if you post the fla
    My letters on the F1 key have faded, how are yours today?

  11. #11
    11 Years Old Boya
    Join Date
    Apr 2004
    Posts
    61
    THANK YOU theTick! Special thank to McUser too!

    localToGlobal() is just what I needed.
    Now my ship can shoot laser from the cannonmc.

    :smile:
    Checkout my site:
    Click HERE
    Checkout my games:
    Oops! No game for now!

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