A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Close last opened door?

  1. #1
    Member
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    40

    Close last opened door?

    I'm setting up a scenario with 12 doors, each with unique (but not sequential) instance names. I've set up a variable that, when a door is clicked, it takes on the instance name of that door. This is working.

    When clicked, the door movieclip plays to a midpoint in it's own timeline and stops (open position). You can close it by clicking the now opened door which returns it to frame one of it's timeline.

    Now, I'm trying to make the next door clicked check first to see if the previously clicked door is still open. If it is, it will make the previously open door play() <----- this will hit the end of the open door's timeline which resets it to frame one > and then play itself and set it's instance name as the new "lastOpened" door variable.

    I was able to manually do it (trying to avoid overlap with neighboring doors) by just directly referring to the instance names so I thought it'd be as simple as dropping the instance name and referring to the variable.

    This worked:

    Actionscript Code:
    // actionscript applied to mc_door3

    on (press) {
            //close door beside first
        if (_root.mc_door2._currentframe >= 2) {
            _root.mc_door2.play();
    }
    // Then open the door now being clicked

        this.play();
        lastOpened = _name;
        trace (lastOpened);
    }

    I tried to do this (with and without the reference to "_root"):

    Actionscript Code:
    on (press) {
            //close door beside first
        if (_root.lastOpened._currentframe >= 2) {
            _root.lastOpened.play();
    }
    // Then open the door now being clicked

        this.play();
        lastOpened = _name;
        trace (lastOpened);
    }

    Any thoughts? Your help is appreciated.

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    You're about to learn something new

    Since lastOpened is actually a variable and only stores the name of the last opened movieclip, but not the movieclip itself, you are then only targeting the variable itself, which is obviously not working. To dynamically access objects, either by only accessing the value of a variable and look for that object, or set different values together to look for an object which make up that name, you can use this:

    scope[variable(s)]

    where scope is a path, either _root, _parent, _global, this or a movieclip for which you want to go inside, and where variable(s) is a variable (or even a string) or variables put together to make up one object. So, you'd use it like this in your context:

    Actionscript Code:
    if (_root[lastOpened]._currentframe >= 2) {
        _root[lastOpened].play();
    }

    notice that there is not dot between the scope and the opening bracket, this is crucial to notice!

    Another example with parts put together:

    Actionscript Code:
    i = 2;
    trace(_root["mc_door"+i]);

    Hope this helps
    I am back, guys ... and finally 18 :P

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

  3. #3
    Member
    Join Date
    Oct 2003
    Location
    Canada
    Posts
    40
    Thanks for the speedy reply...and the lesson

    If I were to just swap those lines in place of what I had should it technically work? I ask because I tried (of course) and it didn't work which makes me thing I've got some other little syntax bug interfering with things.

    As it sits right now I can open and close (click, click) all of the doors but can only manually close the neighboring, overlapping doors (because I manually set it up.

    The primary reason I'm trying to do what I'm trying here is so that only one door can be open at any time but the secondary reason to need this is because I'm getting some shuffling of z-depth on open doors dropping behind closed doors unexpectedly.

    Feel free to give it a try - open a bunch of doors and you should see some start to slip behind closed neighboring doors. You'll see a swapDepth which brings the currently clicked door to the front.

    Surely I've complicated this somewhere here.

    http://www.animatters.com/uploads/Module1_Build2e.zip

  4. #4
    Junior Member
    Join Date
    Feb 2012
    Posts
    2
    ...

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