Please Help with with array an variable

I am having trouble setting the variable for selectedBtn.

I want to have it so I can put selectedBtn = 3; So that when you first open the swf. It will have the last button already selected.

I include my code below. Any help is very much appreciated.

//code
var nameArr:Array = new Array(“page 1”, “page 2”, “page 3”, “page 4”);
var buttArr:Array = new Array (b1, b2, b3, b4);
for (i=0;i<buttArr.length;i++) {
var tmpBtn = buttArr*;
tmpBtn.id = i;

tmpBtn.onRollOver = over;
tmpBtn.onRollOut = out;
tmpBtn.onPress = press;
tmpBtn.onRelease = release;
tmpBtn.buttText.buttonText.text = nameArr*;
}

function over() {
if (_global.selectedBtn != this) {
this.gotoAndPlay(2);
}
}

function out() {
if (_global.selectedBtn != this) {
this.gotoAndPlay(7);
}
}

function press() {
if (_global.selectedBtn != this) {
this.gotoAndStop(17);
this._parent._global.selectedBtn.gotoAndPlay(7);
}
}

function release() {
if (_global.selectedBtn != this)
_global.selectedBtn = this;
this.gotoAndStop(18);

  switch (this.id) {
case 0:    
    getURL(yahoo.com, "_blank");
    break ;
case 1:
    getURL(yahoo.com, "_blank");
    break ;
case 2:
    getURL(yahoo.com, "_blank");
    break ;
case 3:
    getURL(yahoo.com, "_blank");
    break ;

}
}

test this, not sure how your site is set up but this should work:


_global.selectedBtn = null;
var nameArr:Array = new Array("page 1", "page 2", "page 3", "page 4");
var buttArr:Array = new Array (b1, b2, b3, b4);

for (i=0;i<buttArr.length;i++) {
    var tmpBtn = buttArr*;
    tmpBtn.id = i;
    tmpBtn.onRollOver = over;
    tmpBtn.onRollOut = out;
    tmpBtn.onPress = press;
    tmpBtn.onRelease = release;
    tmpBtn.buttText.buttonText.text = nameArr*;
}

function over() {
    if (_global.selectedBtn != this) {
        this.gotoAndPlay(2);
    }
}

function out() {
    if (_global.selectedBtn != this) {
        this.gotoAndPlay(7);
    }
}

function press() {
    if (_global.selectedBtn != this) {
        this.gotoAndStop(17);
        _global.selectedBtn.gotoAndPlay(7);
    }
}

function release() {
    if (_global.selectedBtn != this) {
        _global.selectedBtn.gotoAndPlay(7);
        _global.selectedBtn = this;
        this.gotoAndStop(18);

        switch (this.id) {
            case 0:
                getURL(yahoo.com, "_blank");
                break ;
            case 1:
                getURL(yahoo.com, "_blank");
                break ;
            case 2:
                getURL(yahoo.com, "_blank");
                break ;
            case 3:
                getURL(yahoo.com, "_blank");
                break ;
            default :
                break;

    }
}

Thanks for your help. But It didn’t work. I attached the flash file so it will be easier to see how I built my buttons.

It has some thing to do with making selectedBtn = to a number but I am missing something in the code or just not writing the code properly.

just put this in the last line of your code…

buttArr[3].onPress();

it wil select the last button automatically onload …

[quote=alchris;2334446]Thanks for your help. But It didn’t work. I attached the flash file so

it will be easier to see how I built my buttons.

It has some thing to do with making selectedBtn = to a number but I am missing something in the code or just not writing the code properly.[/quote]

[quote=sparkdemon;2334462]just put this in the last line of your code…

buttArr[3].onPress();

it wil select the last button automatically onload …[/quote]

Thank you so much. That works great!!! Can you also help create a variable for the “selectedBtn” Because I am using this on an html using SWFObject script and flashvars.

Example of how I am going to use:

Page1.html
so.addVariable(“selectedBtn”, “1”);

Page2.html
so.addVariable(“selectedBtn”, “2”);

Figured out the answer to my own question.

instead of buttArr[3].onPress();

buttArr[selectedBtn].onPress();

now
selectedBtn =2; // input number 0-3 to select which button to select on start.