[FMX]Array question ! I think?

I have a movie with a changing background. I load external movies after one of the buttons is pressed and they appear al on a different place.The code to control my buttons is:

function setButton() {
for (var i in menuMc) {
if (menuMc*._name.substr(0, 4) == "btn_") {
clip = menuMc*;
clip.onRollOver = function() {
// etc etc etc......
}
}
}
}

I have a preloader for the external swf’s and that is working fine, but because of the changing backgroud it should appear on different x positions depending which btn_ was pressed. Is there a possibilty to integrate something to make such thing work in my button function.
[color=red]Example:[/color]
When btn_home is pressed the preloader should appear on _x 425 and and when btn_about is pressed on _x 550 etc etc

Thanks in advance

you may be able to get away with something like

clip.onRelease = function() {
preloader_mc._x = this._x;

}
maybe having to add something to this._x depending upon reg points etc.

If instead, you decide that you want to use an array, then it should be very easy because of the ivar property you created before.
put each position in order in the array
myArray =[100,200,300,…]
//the above is not in your function

clip.onRelease = function() {
preloader_mc._x = myArray[this.ivar-1];

}

Hi stringy,

This is the main movie, that ivar part you made is in one of the external swf’s. So what should I do with the array ?

so is this for another set of buttons, just to load in different movies including the one you posted before? (just that the code you posted looks the same as the other movie)

Yes this is the main movie, different movies, incl the one from the earlier threat, are loaded into this one.

well this is how i would do it.
name your buttons btn0,btn1,btn2…
movies to load movie0.swf,movie1.swf,movie2.swf…

numbut = 6 //number of buttons
myArray =[100,200,300…] //_x where you want preloader to appear
for (var i = 0; i<numbut; i++) {
this[“btn”+i].ivar = i;
this[“btn”+i].onPress = function() {
preloader_mc._x = myArray[this.ivar];
loadMovie(“movie”+this.ivar+“.swf”, “container”);
//start preloader function
};
}

Hi stringy,

My buttons are already called: btn_home, btn_service… etc. Does this make any different?

yes

If you are still using the for in loop and the buttons are contained in menuMC(again)
myArray =[100,200,300…] //on the same timeline
function setButton() {
for (var i in menuMc) {
if (menuMc*.name.substr(0, 4) == "btn") {
clip = menuMc*;
clip.ivar = i

etc etc
clip.onRelease = function() {
preloader_mc._x = myArray[this.ivar-1];

}

Thanks stringy :slight_smile:

I was a bit to quik with my thank you. The buttons are indeed in menuMC and I placed the array with the different _x positions at the same timeline I added clip.ivar = i; to the function. I even tried it with a seperate mc (test_mc) what is visible all the time, but it isn’t working

try trace(this.ivar) inside clip.onRelease(){}
is the preloader_mc on the same timeline?

The trace (this.ivar) gives btn_home, btn_service etc but nothing happens otherwise. I even tried it with a seperate mc because off-line (Ctrl-Enter) the preloader isn’t visible.

I have the file attached, maybe you see what i’m doing wrong

Sorry, ive spent 20 mins or so looking at your file and i bet im more confused than you.

Thanks anyway stringy.I will have to think about another solution then :slight_smile: