Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading external swf files

Status
Not open for further replies.

typeofdoug

Programmer
Feb 2, 2007
4
US
I've created (with help) a series of buttons that scroll a movieClip's x-position according to an arrayIndex. With variables, these buttons also cycle through their up and down state as the user clicks from one to the next. I'd like for them to also load an external flash movie into a "loader" movie clip. More precisely, a different external swf for each button.

I don't know how to include the loadMovie script into the (beyond my skills) action script that controls my x-postion buttons. I've tried to write the bellow code for each button, but it stops my x-position scroll.
Code:
controller_mc.but1.onRelease = function() {
	loadMovie("chapterTest.swf", "_root.loader");
};

I know this is not vert clear. Here is my complete code.
Code:
//finds current x pos and sets speed to new x pos
Movieclip.prototype.scrollme1 = function(xPos) {
	cX = this._x;
	difX = cX-xPos;
	this._x = cX-(difX/5);
};
Movieclip.prototype.scrollme2 = function(xPos) {
	cX = this._x;
	difX = cX-xPos;
	this._x = cX-(difX/6);
};
//the three timline arrays
//variable starting value
arrayIndex = 0;
//timeline stopping postions
timeline1Xpos = new Array(2800, 2100, 1400, 700, 0, -700, -1400, -2100, -2800);
//scrolling animation
timeline1.onEnterFrame = function() {
	this.scrollme1(timeline1Xpos[arrayIndex]);
};
//variable starting value
arrayIndex = 0;
//timeline stopping postions
timeline2Xpos = new Array(2800, 2100, 1400, 700, 0, -700, -1400, -2100, -2800);
//scrolling animation
timeline2.onEnterFrame = function() {
	this.scrollme2(timeline2Xpos[arrayIndex]);
};
//buttons that scroll the timeline to specific x positions
//but1,2,3,4,5,6,7,8, all here
for (var i = 1; i<=8; i++) {
	controller_mc.but1.gotoAndStop("down");
	controller_mc["but"+i].i = i;
	controller_mc["but"+i].onRollOver = function() {
		this.frameHold = this._currentframe;
		this.gotoAndStop("over");
	};
	controller_mc["but"+i].onRollOut = function() {
		this.gotoAndStop(this.frameHold);
	};
	controller_mc["but"+i].onRelease = function() {
		butRelease(this);
	};
}
function butRelease(obj) {
	this = obj;
	arrayIndex = this.i-1;
	for (var mc in this._parent) {
		var thisHold = this;
		if ((this._parent[mc] == thisHold) && (this._parent[mc]._name.indexOf("but") != -1)) {
			this._parent[mc].gotoAndStop("down");
		} else {
			this._parent[mc].gotoAndStop("up");
		}
	}
	this.frameHold = this._currentframe;
}
//timeline forward and backward buttons
controller_mc.goForward.onRelease = function() {
	if (arrayIndex<7) {
		butRelease(this._parent["but"+(arrayIndex+2)]);
	}
};
controller_mc.goBack.onRelease = function() {
	if (arrayIndex>0) {
		butRelease(this._parent["but"+(arrayIndex)]);
	}
};
//external links
controller_mc.but1.onRelease = function() {
	loadMovie("chapterTest.swf", "_root.loader");
};
timeline1.link01.onRelease = function() {
	loadMovie("linkTest.swf", "_root.loader");
};

Here is a link to my file
<
I'll appreciate any help you are able to offer and am happy to answer questions if you need me to be more clear. Thanks
 
You may do it like this:
Code:
function butRelease(obj) {
    this = obj;
    arrayIndex = this.i-1;
    for (var mc in this._parent) {
        var thisHold = this;
        if ((this._parent[mc] == thisHold) && (this._parent[mc]._name.indexOf("but") != -1)) {
            this._parent[mc].gotoAndStop("down");
        } else {
            this._parent[mc].gotoAndStop("up");
        }
    }
    this.frameHold = this._currentframe;
    [b]switch (obj._name) {
	case "but1" :
		loadMovie("chapterTest.swf", "_root.loader");
		break;
	}[/b]
}

Kenneth Kawamoto
 
Big help. Thank you! It seems to be working fine. I'm not familiar with that last line of code... break;

i'm writing my buttons like this...

this.frameHold = this._currentframe;
switch (obj._name) {
case "but1" :
loadMovie("chapterTest.swf", "_root.loader");
break;
case "but2" :
loadMovie("chapterTest.swf", "_root.loader");
break;
}
}


It's working, but I'm wondering if it is proper.
 
Yes it is proper. "break" is required otherwise the next "case" statement will be executed.

You can do it like this as well.
Code:
var mov;
switch (obj._name) {
   case "but1" :
      mov = "chapterTest.swf";
      break;
   case "but2" :
      mov = "chapterTest.swf";
      break;
}
loadMovie(mov, "_root.loader");

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top