A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Set visibility

  1. #1
    Expression...7 mullz's Avatar
    Join Date
    Jun 2000
    Location
    England
    Posts
    366

    Set visibility

    Hi all, aint posted for ages but here goes!!

    I have 10 geographical maps which I want to be able to set the visibilty of with 10 buttons.

    so I have 10 maps one on top of the other.

    I have 10 buttons

    all maps have instance names of map1 etc..

    when I click "button 1" I want "map1" to appear but the button to stay in the over state.

    then when I click "button 1" again I want "map1" to disappear and the button to go back to a normal state.

    Same goes for the other buttons maps..

    Cheers If anyone can help!

    David
    .

    www.expression7.com
    __________________

  2. #2
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    So what's the problem? Setting the maps' visibilities, or keeping the buttons' selected states while the corresponding maps are visible?
    Or both?

    Are you buttons all similar in design, outside of maybe some different text?

  3. #3
    Expression...7 mullz's Avatar
    Join Date
    Jun 2000
    Location
    England
    Posts
    366
    OK I have on "map1"

    onClipEvent (load) {
    setProperty("_root.map15", _visible, "0");
    }

    and on "button1" I have

    on (release) {
    if ("_root.map15", _visible, "0") {
    setProperty("_root.map15", _visible, "1");
    } else {
    setProperty("_root.map15", _visible, "1");
    }
    }

    All the buttons are the basic flash mx oval ones

    Cheers
    .

    www.expression7.com
    __________________

  4. #4
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    That's old Flash 4 syntax...

    Try...
    code:

    onClipEvent (load) {
    this._visible = false;
    }

    //And on "button1"...

    on (release) {
    if (_root.map15._visible == false) {
    _root.map15._visible = true;
    } else {
    _root.map15._visible = false;
    }
    }


  5. #5
    Junior Member
    Join Date
    Jun 2004
    Posts
    12
    Originally posted by mullz
    OK I have on "map1"

    onClipEvent (load) {
    setProperty("_root.map15", _visible, "0");
    }

    and on "button1" I have

    on (release) {
    if ("_root.map15", _visible, "0") {
    setProperty("_root.map15", _visible, "1");
    } else {
    setProperty("_root.map15", _visible, "1");
    }
    }

    All the buttons are the basic flash mx oval ones

    Cheers
    I'm just wondering, why do you have an: if ("_root.map15", _visi...

    if you take away some lines so i would be like this:
    Code:
    on (release) {
            setProperty("_root.map15", _visible, "1");
    }
    I am a noob, but i think that would have the same effect..

  6. #6
    Expression...7 mullz's Avatar
    Join Date
    Jun 2000
    Location
    England
    Posts
    366
    WOW! Thats great!

    Its work perfect..

    Do you know how when the map is visible the button stays in the over state?

    Cheers ever so much for your help!
    .

    www.expression7.com
    __________________

  7. #7
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    My code? Or Grantax's?

    That asked, Grantax... The if statement might be needed so the button acts as a toggle, changing the visibility on or off, on each button press.

    As for keeping a button in a selected state while the corresponding map is up, it can be done in severals ways. Each button in a 2 frames movie clip, with stop actions on both frames, and only the "selected" state on frame 2. Thus on each button's press, the movie clip is moved to the other frame, and the button seems to stay selected, or returns to the normal state on another press.

  8. #8
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    if you used something like this.....

    Code:
    /// code on frame in root of movie (where maxNum = the number of maps)
    function setMap(ID) {
        for(i=1;i<=maxNum;i++){
            if(i==ID){
                eval("map"+i)._visible = true;
                eval("button"+i).enabled = false;
            } else {
                eval("map"+i)._visible = false;
                eval("button"+i).enabled = true;
            }
        }
    }
    
    /// code on button (in this example all buttons are in the root)
    on (release){
        setMap(1); // where 1 corresponds to the map number
    }
    then that would keep only the map you selected visible and all other maps invisible. It would also disable your buttons accordingly.

    I have never seen a way of changing a button's state via script.
    You could do this by creating movieClips and programme them to act like buttons (with the added advantage of being able to set the state with AS).
    Or you could achieve a similar effect by changing the tint of the button with a colour transform object and add that to the code above.

    __________________________________________________ ___________________

    To toggle visibility you do not need an if statement, you just need...
    Code:
    map15._visible = !map15._visible;
    __________________________________________________ ___________________

    enjoy
    Last edited by Lexicon; 06-22-2004 at 11:24 AM.
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

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