dcsimg
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Determining Variable States

Hybrid View

  1. #1
    Registered User
    Join Date
    Mar 2001
    Posts
    46
    Hi

    I have a number of mc's (drawers) that each have a variable assigned to them (d1, d2 etc...) the variable is either equal to "open" or "closed"

    when a single button is clicked I need to be able to perform a "goToandPlay" action on whichever of the mc's variable is equal to "open"

    is this possible?

    I have built an array that goes like this,

    drawersArray = newArray
    drawersArray[d1]
    drawersArray[d2]

    etc....

    *when traced this returns the correct values, i just need to be able to identify which are set to "open" then control each mc that is.

    do i need the "for in" command (as someone else suggested?

    please help, i have confused myself here :S

    cheers 3quid

  2. #2
    Senior Front End Developper
    Join Date
    Dec 2000
    Location
    Montréal
    Posts
    568
    I'm not sure where your variable are set, but if your array contain the "closed" and "open" value you could check your value like this:

    Code:
    for (var j= 0; j < drawersArray.length; j++)
    {
         if (drawersArray[j] == "open")
         {
             //place your code here
         }
    }

  3. #3
    Member
    Join Date
    Jul 2001
    Posts
    32
    another way would be instead of having an array for all drawers, just have one variable wich contains the name or number of the opened drawer.
    just a little less complex, your way is fine though and charles solution'll work.

    bye

  4. #4
    Registered User
    Join Date
    Mar 2001
    Posts
    46

    cheers... but!

    Hi

    I must be being thick or summink cos i cant get that to work!

    i c wot u r doing but i dont see how it is refrencing to the instance of the clip it needs to.

    say i have the instances drawer3 and drawer5 "open" the array will read.

    drawersArray[0] == "closed"
    drawersArray[1] == "closed"
    drawersArray[2] == "open"
    drawersArray[3] == "closed"
    drawersArray[4] == "open"

    how does it know that drawersArray[2] means that drawer3 instance is in the open position?

    sorry if that is a dumb **** question, as u have probably gathered I am not that experienced at actionscript.

    cheers anyway

    3quid


  5. #5
    Senior Front End Developper
    Join Date
    Dec 2000
    Location
    Montréal
    Posts
    568
    okay you need to associate your action with the array.

    for example, at start all you drawer are closed, so you need to set all the variables to "closed".

    when you click on the drawer to open it, you need to change the value:

    Code:
    on (release)
    {
         if (drawersArray[3] == "closed")
         {
              drawersArray[3] = "open";
              //place the rest of your code here when you open
         }
         else
         {
              drawersArray[3] = "closed";
              //place the rest of your code here when you close
         }
    }

  6. #6
    Registered User
    Join Date
    Mar 2001
    Posts
    46

    confusion

    hi

    ok cheers for that

    but... (u knew that was coming!) the drawers work fine and change their variable, but as u can have as many open as u like at one time (6 of them), i still dont get how u target the correct clip (1 of 6)

    the array (drawersArray) variables are set when the drawer clips load (on a frame action) and are changed when their individual buttons are clicked (the individual buttons are not in the drawer clip that they control but on a diff layer, so that i only need one drawer symbol)

    so after this if say it works out that drawersArray[3] and drawersArray[5] is set to "open , i need to target mcclip's "drawer3" and "drawer5".

    how does that work?

    maybe i am jus missing the point of wot u r saying? sorry if i am!

    3quid

    ps if i am being a _ _ _ _ _ (fill in as necessary!) say so!







  7. #7
    Senior Front End Developper
    Join Date
    Dec 2000
    Location
    Montréal
    Posts
    568
    you need to know the relationnionship between the real movie clip and the array.

    drawersArray[0] = drawer1;
    drawersArray[1] = drawer2;
    drawersArray[2] = drawer3;
    etc.

    then the for loop

    Code:
    for (var j= 0; j < drawersArray.length; j++)
    {
         if (drawersArray[j] == "open")
         {
             openMC = eval("drawer" + (j + 1));
             //now you can use an open drawer using openMC
             //examples:
             openMC.gotoAndPlay(4);
             openMC._alpha = 75;
         }
    }

  8. #8
    Registered User
    Join Date
    Mar 2001
    Posts
    46

    Smile Thankyou Thankyou Thankyou

    Cheers for all ya help and patience mate.

    I quite honestly wouldnt have worked that out, if it werent for your help i would still be punching things!

    Now i have learnt that it opens up loads more possibilities

    anyway cheers again and i shall put u in the credits. will post the site when its complete.

    3quid

  9. #9
    Senior Front End Developper
    Join Date
    Dec 2000
    Location
    Montréal
    Posts
    568
    No problem...

    glad it helped...

    Martin

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