dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Need help with functions

  1. #1
    Hi, I'm still learning Flash actions scripting and I need some help with functions. I'm building a website and have the following script on several buttons. The script for each button is basically the same, save the value of a few variables. Here's the script:

    on (release) {
    _root.section = "theband";
    _root.homehighlight._visible = false;
    _root.thebandhighlight._visible = true;
    _root.discographyhighlight._visible = false;
    _root.contactmehighlight._visible = false;
    _root.downloadshighlight._visible = false;
    _root.funstuffhighlight._visible = false;
    _root.linkshighlight._visible = false;
    _root.x = 129;
    if (_root.x>_root.moviePosition) {
    tellTarget ("_root.sliderConroller") {
    gotoAndPlay(2);
    }
    } else if (_root.x<_root.moviePosition) {
    tellTarget ("_root.sliderConroller") {
    gotoAndPlay(4);
    }
    }
    }
    on (rollOver) {
    _root.button = theband;
    tellTarget ("_root.buttonfadecontroller") {
    gotoAndPlay(2);
    }
    }
    on (rollOut) {
    tellTarget ("_root.buttonfadecontroller") {
    gotoAndPlay(4);
    }
    }

    So the only difference between each button will be the value of the variable _root.section, the visibility of movie clips, the value of variable _root.x and the value of the variable _root.button. How would i go about putting this in a function on frame 1 and then just calling the function when the button is pressed. I know how to actually make the function, but I don't know how to change the value of those variables from button to button. Please help. I would be greatly appreciated.

  2. #2
    Please help, I know my coding is very crude, but I'm really trying to learn here. Any help is greatly appreciate

  3. #3
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    A function like yours must have arguments in the parenthesis, which point to the objects you want to change:
    For some things you need a loop if you have more than one item which changes in the same manner like _visible = false. Also tell target is deprecated so don't use any more
    _root.x = 179 will give you an error message. You can only write x=179.


    function changeAll(highLights,moviePosition,x,button) {
    _root.section = "theband";
    _root.highLights._visible = false;

    if (_root.x>_root.moviePosition) {
    tellTarget ("_root.sliderConroller") {
    gotoAndPlay(2);
    }
    } else if (_root.x<_root.moviePosition) {
    tellTarget ("_root.sliderConroller") {
    gotoAndPlay(4);
    }
    }
    }
    on (rollOver) {
    tellTarget ("_root.button.fadecontroller") {
    gotoAndPlay(2);
    }
    }
    on (rollOut) {
    tellTarget ("_root.button.fadecontroller") {
    gotoAndPlay(4);
    }
    }

    on (release) {
    changeAll(homehighlight,200,129,theband)
    }
    Hope that will help you .

  4. #4
    Thanks! That's a HUGE help. I have one more question. I need to find a simpler way to do the following actions:

    _root.homehighlight._visible = false;
    _root.thebandhighlight._visible = true;
    _root.discographyhighlight._visible = false;
    _root.contactmehighlight._visible = false;
    _root.downloadshighlight._visible = false;
    _root.funstuffhighlight._visible = false;
    _root.linkshighlight._visible = false;

    Basically those are movie clips, each with highlighted states of buttons. When the user clicks a button the corresponding movie clip is made visible and all other are made invisible. Does anyone know an easier way to do this? I don't want to have so much redundant script on each button. Thanks again for your help.

  5. #5
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    call these actions something light_1, light_2 etc. Then make a loop:

    count = 1;
    for (count=1;count<=6;count++) {
    _root["light_" + count]._visible = false;
    _root.light_7._visible = true;
    }

    put this code somewhere inside the function.

  6. #6
    thanks! So instead of calling my movie clips _root.homehighlight you're saying I should call them light_1, light_2, etc.? So if I put them in the changeAll function how do I state in the function specifically which button I want visible and which ones should be invisible?

    Sorry I'm asking so many questions. I'm trying to understand how this all works. It's much better for me to actually understand how these things work than just copy and paste your code.

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