dcsimg
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: functions, arrays, loading objects from 1 frame to another

  1. #1
    Member
    Join Date
    Jun 2002
    Posts
    38
    ok i have 2 questions to ask.

    1 : Functions - how do I create a function and then i tell another command line to look inside my function and perform that command line

    Example ;-

    function tingting {
    _root.ting_btn1._visible = true
    _root.ting_btn2._visible = true
    _root.ting_btn3._visible = true
    }

    _root.tingting.ting_btn2

    Also i want it to show "tingting_btn2" inside another frame. how do i do this with script?


    2 : Arrays - How do i create my own groups using script?

    Example ;-

    *THIS IS NOT REAL CODING AM GUESSING*

    Group tinggroup ("ting_btn1, ting_btn2, ting_btn3")

    _root.tinggroup._visible = false


  2. #2
    HELP>>>ACTIONSCRIPT DICTIONARY
    Join Date
    Feb 2000
    Location
    In the Present Moment
    Posts
    1,041
    1) Controlling one element

    I think you want to be able to turn on and off single elements and use a function to do so. This function will toggle the _visible property, between on and off, of whatever clip you send as the parameter-

    Code:
    function toggle ( thisItem) {
         if(thisItem._visible=0){//if you can't see me
              thisItem._visible=1;//see me
         }else{ //oh, you can already see me
              thisItem._visible=0; //so turn around already, don't look
         }
    }
    and this is how you call the function in AS:

    _root.toggle ( _root.ting_btn2);

    or

    _root.toggle ( clipName );

    As to showing the name of this clip that you are affecting, that can be done with the same button that you used to call this function. I am not sure how you want the name displayed, but I imagine that you have a dynamic text field set up? If so, then just use _root.textFieldName="ting_btn2"'; on the same button that you use to call the function, as in:
    Code:
    on(release){
         _root.toggle(_root.ting_btn2);
         _root.textFieldName="ting_btn2";
    }
    2) To make an array -
    Code:
    tingGroup=new Array(); //one way to declare an array
    tingGroup[0]=ting_btn1;//adding elements the long way
    tingGroup[1]=ting_btn2;
    tingGroup[2]=ting_btn3;
    
    or you could simply do it this way 
    
    tingGroup=[ting_btn1,ting_btn2,ting_btn3];
    //if you are storing strings in the array, each element is surrounded by quotes
    //as in: boardID=["xanbarian","Antibody","etc"];
    Now then, let's make a function that sets the _visible property of the objects in any array to off or false -
    Code:
    function buttonsOff ( thisArray ){
         for(n=0;n lessthan thisArray.length;n++){
              _root[ tingGroup[ n ] ]._visible=false;
         }
    }
    
    How about a function that sets their _visible property to on or true:
    
    function buttonsOn ( thisArray ){
         for(n=0;n lessthan thisArray.length;n++){
              _root[ tingGroup [ n ] ]._visible=true;
         }
    }
    Please note the lessthan from the above code should be the less than sign (shift comma). For some reason I can't post it without it goofing up my post.

    To call these functions:

    _root.buttonsOff(_root.tingGroup);

    or

    _root.buttonsOn (_root.tingGroup);

    This is assuming that the functions are written on the _root timeline. If you put this stuff in MovieClips, just make sure that your paths are correct.

    Good Luck!




  3. #3
    Member
    Join Date
    Jun 2002
    Posts
    38
    WOW O.O best reply i ever had on Flash Kit thx's man!

    love it can't w8 to see it in action

  4. #4
    HELP>>>ACTIONSCRIPT DICTIONARY
    Join Date
    Feb 2000
    Location
    In the Present Moment
    Posts
    1,041
    You're welcome!

    Now, do you understand it? ;p

    Let me know how it goes. heh

  5. #5
    Member
    Join Date
    Jun 2002
    Posts
    38
    yep i totally understand it ... but now i got a couple more questions after ur excellent explantion

    Code:
    function toggle ( thisItem) {
         if(thisItem._visible=0){//if you can't see me
              thisItem._visible=1;//see me
         }else{ //oh, you can already see me
              thisItem._visible=0; //so turn around already, don't look
         }
    }
    "( thisItem)" if i had more than 1 item do i tell this line of code "( thisItem)" to be like this "( thisItem1, thisItem2, thisItem3)" ????


    last question ........ maybe



    Code:
    function buttonsOff ( thisArray ){
         for(n=0;n > thisArray.length;n++){
              _root[ tingGroup[ n ] ]._visible=false;
         }
    }
    
    ----------------------------------------------------------------------------------------------------------------------
    
    function buttonsOn ( thisArray ){
         for(n=0;n > thisArray.length;n++){
              _root[ tingGroup [ n ] ]._visible=true;
         }
    }
    can the "n" value be changed to anything like for exmaple "number"

  6. #6
    HELP>>>ACTIONSCRIPT DICTIONARY
    Join Date
    Feb 2000
    Location
    In the Present Moment
    Posts
    1,041
    Well in the examples that I laid out above there is a function for turning a single movieClip on or off and one to turn multiple movieClips, from an array, on and off .

    So to answer the first question, no you would not address it the way you suggest. If you wanted to turn multiple, solitary movie Clips on and off and you did not store their names in an array, you would make a line of code for each individual clip as in:

    toggle(_root.clip1);
    toggle(_root.otherClip);
    toggle(_root.room.lightSwitch);

    or if they happened to be name sequentially, (_root.clip0,_root.clip1,_root.clip2) you could use:

    for(n=0;n<3;n++){
    toggle(_root["clip"+n]);
    }

    or if they were stored in an array, _root.switchList=[_root.clip1,_root.clip2,_root.clip3];

    you would use the buttonsOn (_root.switchList); or buttonsOff (_root.switchList);

    (note: make sure that those >greater than signs are turned into less than < signs in the actual code. )

    The n is arbitrary. That is just used as a loop counter so you could call it whatever you want. I wouldn't personally use number as a variable name though. Number() is used to change or make sure that a variable is a number. Such as,

    someVar="7";
    someOtherVar=4;
    tempVar=someVar + someOtherVar;

    tempVar would be 74

    someVar is a String in this case, if I want someVar to be considered a number I would change tempVar to be

    tempVar = Number(someVar) + someOtherVar;

    tempVar would then equal 11


    Did that answer your questions?

    If not, i'm around.


  7. #7
    Member
    Join Date
    Jun 2002
    Posts
    38
    yes it did answer my question . Thx's man once again a very BIG thx's

  8. #8
    HELP>>>ACTIONSCRIPT DICTIONARY
    Join Date
    Feb 2000
    Location
    In the Present Moment
    Posts
    1,041
    You're welcome Xan.

    See you around the Kit eh?


  9. #9
    Member
    Join Date
    Jun 2002
    Posts
    38
    Originally posted by Antibody
    You're welcome Xan.

    See you around the Kit eh?

    o will be around

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