View Full Version : Coding array and function
onsitus
November 6th, 2005, 11:30 AM
This code works fine for loading a pic into a created container and placed centered in a box_mc.
I am trying with no luck to have the same thing repeat itself x number of time.
My idea is:
array=[1, 2, 3];
var a = 0;
if (a< array.length){ a++;}
then apply the underneath code until a = array.length
changing all the 1 with the value of a, so to load each pic1,2 and 3 in different box_mc1, 2, 3 (still being centered).
:d:
createEmptyMovieClip("container1", 1);
function preload1(pic1) {
loaded = pic1.getBytesLoaded();
total = pic1.getBytesTotal();
if (loaded>=total && loaded>0) {
clearInterval(myinterval1);
w1 = pic1._width;
h1 = pic1._height;
trace(w1);
trace(h1);
container1._x = box_mc1._x+(box_mc1._width-w1)/2;
container1._y = box_mc1._y+(box_mc1._height-h1)/2;
}
}
loadMovie("pic1.jpg", "container1");
myinterval1 = setInterval(preload1, 50, container1);
PS:I did read many post about XML but would like to stick to AS. I am trying to learn one thing at the time.:to:
Thank you.
stringy
November 6th, 2005, 11:47 AM
This code works fine for loading a pic into a created container and placed centered in a box_mc.
I am trying with no luck to have the same thing repeat itself x number of time.
My idea is:
array=[1, 2, 3];
var a = 0;
if (a< array.length){ a++;}
then apply the underneath code until a = array.length
changing all the 1 with the value of a, so to load each pic1,2 and 3 in different box_mc1, 2, 3 (still being centered).
:d:
createEmptyMovieClip("container1", 1);
function preload1(pic1) {
loaded = pic1.getBytesLoaded();
total = pic1.getBytesTotal();
if (loaded>=total && loaded>0) {
clearInterval(myinterval1);
w1 = pic1._width;
h1 = pic1._height;
trace(w1);
trace(h1);
container1._x = box_mc1._x+(box_mc1._width-w1)/2;
container1._y = box_mc1._y+(box_mc1._height-h1)/2;
}
}
loadMovie("pic1.jpg", "container1");
myinterval1 = setInterval(preload1, 50, container1);
PS:I did read many post about XML but would like to stick to AS. I am trying to learn one thing at the time.:to:
Thank you.
try this
marray = [1, 2, 3];
var a = 0;
createEmptyMovieClip("checker", -5500);
createEmptyMovieClip("container1", 1);
function preload1(pic1) {
loadMovie("pic"+marray[a]+".jpg", "container1");
a<marray.length-1 ? a++ : a=0;
clearInterval(myinterval1);
checker.onEnterFrame = function() {
loaded = pic1.getBytesLoaded();
total = pic1.getBytesTotal();
if (loaded>=total && loaded>0) {
delete this.onEnterFrame;
w1 = pic1._width;
h1 = pic1._height;
trace(w1);
trace(h1);
container1._x = box_mc1._x+(box_mc1._width-w1)/2;
container1._y = box_mc1._y+(box_mc1._height-h1)/2;
myinterval1 = setInterval(preload1, 2000, container1);
}
};
}
myinterval1 = setInterval(preload1, 50, container1);
onsitus
November 6th, 2005, 12:05 PM
Thank you stringy, not really the effect I was looking for (it loads one pic after the other in the box_mc) but I will see from there if I can load them in their respective box_mc (once I understood fully the as u posted (0:)
stringy
November 6th, 2005, 12:36 PM
Thank you stringy, not really the effect I was looking for (it loads one pic after the other in the box_mc) but I will see from there if I can load them in their respective box_mc (once I understood fully the as u posted (0:)
oops- i did not read your original question properly
marray = [1, 2, 3];
var a = 0;
createEmptyMovieClip("checker", -5500);
for (var i = 1; i<4; i++) {
createEmptyMovieClip("container"+i, i);
}
function preload1(pic1) {
var b = marray[a];
pic1.loadMovie("pic"+b+".jpg");
clearInterval(myinterval1);
checker.onEnterFrame = function() {
trace(pic1);
var loaded = pic1.getBytesLoaded();
var total = pic1.getBytesTotal();
if (loaded>=total && loaded>0) {
delete this.onEnterFrame;
var w1 = pic1._width;
var h1 = pic1._height;
pic1._x = this._parent["box_mc"+b]._x+(this._parent["box_mc"+b]._width-w1)/2;
pic1._y = this._parent["box_mc"+b]._y+(this._parent["box_mc"+b]._height-h1)/2;
trace(container1._x);
trace(container1._y);
if (a<marray.length-1) {
a++;
myinterval1 = setInterval(preload1, 50, this._parent["container"+Number(a+1)]);
}
}
};
}
myinterval1 = setInterval(preload1, 50, this["container"+marray[a]]);
onsitus
November 6th, 2005, 02:48 PM
Wow, wonderful Stringy. :thumb: I can't thank you enough.
I only got to the point of
for (var i = 1; i<4; i++) {
createEmptyMovieClip("container"+i, i);
} (really I had a <=3 instead of <4)before being stuck. That was like 3 hours ago. :ne:
I just need to figure out how it works now!
stringy
November 6th, 2005, 02:53 PM
Wow, wonderful Stringy. :thumb: I can't thank you enough.
I only got to the point of
for (var i = 1; i<4; i++) {
createEmptyMovieClip("container"+i, i);
} (really I had a <=3 instead of <4)before being stuck. That was like 3 hours ago. :ne:
I just need to figure out how it works now!
glad it works ok; its not really far away from your original script but let me know if there is anything not clear.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.