A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Actionscript to move symbol to front?

  1. #1
    Senior Member
    Join Date
    Dec 2002
    Posts
    156

    Actionscript to move symbol to front?

    Is there a line of actionscript which can be used to make a symbol arrange to the front (of its current layer, at least)?

    So for example:

    symbol1.onPress = function () {
    startDrag (this, false);
    //code here to make symbol1 appear on top / at the front of this layer
    }

    Thanks in advance

  2. #2
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    As far as flash is concerned once the movie is published , you can imagine everything as being on ONE single layer, with things at varying depths(according to the layer they where on at author time or the depth they have been placed at dynamically)

    if you want to change the depth of a movieclip you can use for e.g

    Code:
    symbol1.swapDepths(_root.getNextHighestDepth());
    this will put it above everything else... if you want to swap the depths of symbol1 with symbol2 you can use

    Code:
    symbol1.swapDepths(symbol2);
    you cannot say put this movieclip at the top of the current layer (although you could do calculations based upon knowing the other objects on that layer, determining their depths and swapping the depths accordingly)
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  3. #3
    Senior Member
    Join Date
    Dec 2002
    Posts
    156
    Thanks, I think the top code is best for me.

    In my example i'm using a startDrag code, so my symbol will now be at the top on dragging. For my onRelease code (stopDrag) is there a command to say 'go back to the depth you came from'... I wouldnt know what this depth would actually be however, just no longer the top.

  4. #4
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    Code:
    var originalDepth:Number;
    
    symbol1.onPress = function():Void {
    	originalDepth = this.getDepth();
    	this.swapDepths(_root.getNextHighestDepth());
    	this.startDrag();
    };
    
    symbol1.onRelease = function():Void {
    	this.swapDepths(originalDepth);
    	this.stopDrag();
    };
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  5. #5
    Senior Member
    Join Date
    Dec 2002
    Posts
    156
    great! thankyou very much.

    in reference to this line of code:
    symbol1.swapDepths(symbol2);

    i'd actually like symbol1 to swap depth with symbol 2 (or at least go one depth higher) but symbol 2 not to inherit the depth of symbol 1, but stay the same.. is this possible?

  6. #6
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    well two movieclips cannot occupy the same depth at the same time..so you would have to make symbol1 go at least one depth higher than symbol2 ... you could do that like

    Code:
    symbol1.swapDepths(symbol2.getDepth()+1);
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  7. #7
    Senior Member
    Join Date
    Dec 2002
    Posts
    156
    thankyou, you are very kind.

  8. #8
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    no problem everyone helps everyone here
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

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