A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Click and object appears as top-most layer

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    3

    Click and object appears as top-most layer

    As written in the title, how do I make this work?
    I need step-by-step tutorial, so please give me some help here (:

    An example:
    http://www.y8-games.net/games/Sandwich_Maker

    At the left side, see the bread and all the ingredients?
    When you click on any one object, it appears on the top most.

    Yeah, that's what I want to know.
    Hope someone will help me. Thanks.

    *edited*
    PS I'm using AS2 (:
    Last edited by devamind; 11-03-2010 at 11:24 PM. Reason: additional details

  2. #2
    Senior Member
    Join Date
    Jul 2008
    Posts
    391
    AS2 or AS3? If it's AS3 then
    PHP Code:
    someobject.addEventListener (MouseEvent.MOUSE_DOWNonMouseDownfalse0true);
    function 
    onMouseDown (e:MouseEvent) {
        
    e.target.parent.setChildIndex (e.targete.target.parent.numChildren 1);

    That's how you can do it in general.

    e.target is the object that caused the event listener to go off, in this case it's someobject.

    .parent is the parent of whatever is in front of the dot, so it's the parent of the target that set off the event listener.

    setChildIndex (object, index) is a displayobjectcontainer's method that pretty much moves its children from top to bottom or vise versa, an index of 0 is the very bottom, you set it to e.target.parent.numChildren - 1 so the index will be however many children the container has minus 1 so it'll always be on top, minus 1 because it's zero-indexed.
    Last edited by 5Five555; 11-03-2010 at 09:16 PM.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    3
    I'm sorry, but I'm a beginner in this... Could you pls elaborate on where I gotta place this script at? Do I need to change anything to the instance's name or anything like that?

    Thanks!

Tags for this Thread

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