[quoted text, click to view] "jkwilkerson" <webforumsuser@macromedia.com> wrote in message
news:duif9a$i2t$1@forums.macromedia.com...
> Fellow Flasher,
>
> I have an issue. Can anyone take a look at the included script and give me
> an
> idea of how to tidy it up? Basically I would like to know if there is a
> call or
> function that I can do to condense the last nine button calls. I am
> creating
> the "buttons" dynamically and I would like to assign the button function
> to
> each button dynamically.
>
>
>
> for (k=1; k<10; k++) {
> this.createEmptyMovieClip("button"+k, 110+k);
> this["button"+k].lineStyle(1, 0x000000, 100);
> this["button"+k]._x = 55+(70*k);
> this["button"+k]._y = 0;
> this["button"+k].beginFill(0xCCCCCC, 10);
> this["button"+k].moveTo(0, 0);
> this["button"+k].lineTo(0, 80);
> this["button"+k].lineTo(60, 80);
> this["button"+k].lineTo(60, 0);
> this["button"+k].endFill(0, 0);
> button1.onRelease = function() {
> unloadMovie("pcardZone");
> loadMovie("pcard1.swf", pcardZone);
> };
> button2.onRelease = function() {
> unloadMovie("pcardZone");
> loadMovie("pcard2.swf", pcardZone);
> };
> button3.onRelease = function() {
> unloadMovie("pcardZone");
> loadMovie("pcard3.swf", pcardZone);
> };
> button4.onRelease = function() {
> unloadMovie("pcardZone");
> loadMovie("pcard4.swf", pcardZone);
> };
> button5.onRelease = function() {
> unloadMovie("pcardZone");
> loadMovie("pcard5.swf", pcardZone);
> };
> button6.onRelease = function() {
> unloadMovie("pcardZone");
> loadMovie("pcard6.swf", pcardZone);
> };
> button7.onRelease = function() {
> unloadMovie("pcardZone");
> loadMovie("pcard7.swf", pcardZone);
> };
> button8.onRelease = function() {
> unloadMovie("pcardZone");
> loadMovie("pcard8.swf", pcardZone);
> };
> button9.onRelease = function() {
> unloadMovie("pcardZone");
> loadMovie("pcard9.swf", pcardZone);
> };
> }
>
I may be mistaken, but it looks like you are setting up your onRealease for
the 9 buttons 9 times.
Not tested, but should be a starter:
for (k=1; k<10; k++) {
myMC:MovieClip = this.createEmptyMovieClip("button"+k, 110+k);
myMC.lineStyle(1, 0x000000, 100);
myMC._x = 55+(70*k);
myMC._y = 0;
myMC.beginFill(0xCCCCCC, 10);
myMC.moveTo(0, 0);
myMC.lineTo(0, 80);
myMC.lineTo(60, 80);
myMC.lineTo(60, 0);
myMC.endFill(0, 0);
activateButton(myMC, k);
}
function activateButton(mc:MovieClip, k:Number) {
mc.onRelease = function() {
unloadMovie("pcardZone");
loadMovie("pcard" + k + ".swf", pcardZone);
}
}