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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm just not getting it - MovieClip as button loads file 1

Status
Not open for further replies.

rossi3713

Technical User
Feb 18, 2004
18
US
I would greatly appreciate any help on this dilemma.

What I am trying to do is use four movie clips as buttons to load and unload different .swf files into an empty movie clip on the stage.

The first portion of code is what is in my buttons and the second part is what is on my main timeline calling the swf files to load in the empty movie clip called container.

What am I missing?
Do I have it all wrong?

My movieClip button code:

// Create clip
this.createEmptyMovieClip("button1",2);
//Add Text
this.button1.createTextField("submit_txt",1, 0, 0, 50, 20);
this.button1.submit_txt.text = "Movie #1";
//define Button
this.button1.onRelease = function() {
}

On the main time line I have the following code:

on (press) {
function container(){
}
_root.createEmptyMovieClip("container",25);
loadMovie("ex_1.swf", "container");
container._x = 200;
container._y = 50;
}


 
Almost there! Don't use "on(press)", you can do everything from the main timeline:

[tt]// Main timeline
// Create clip
this.createEmptyMovieClip("button1", 2);
//Add Text
this.button1.createTextField("submit_txt", 1, 0, 0, 50, 20);
this.button1.submit_txt.text = "Movie #1";
//define Button
this.button1.onRelease = function() {
container = this._parent.createEmptyMovieClip("container", 25);
container.loadMovie("ex_1.swf");
container._x = 200;
container._y = 50;
};
[/tt]

Kenneth Kawamoto
 
I tried laying the code on the main time line but that didn't work and I got the following.

**Error** Scene=Scene 1, layer=nav, frame=1:Line 3: Statement must appear within on/onClipEvent handler
this.createEmptyMovieClip("button1", 2);

**Error** Scene=Scene 1, layer=nav, frame=1:Line 5: Statement must appear within on/onClipEvent handler
this.button1.createTextField("submit_txt", 1, 0, 0, 50, 20);

**Error** Scene=Scene 1, layer=nav, frame=1:Line 6: Statement must appear within on/onClipEvent handler
this.button1.submit_txt.text = "Movie #1";

**Error** Scene=Scene 1, layer=nav, frame=1:Line 8: Statement must appear within on/onClipEvent handler
this.button1.onRelease = function() {

Total ActionScript Errors: 4 Reported Errors: 4

_____________________________________________

I tried the following on the movieclip button with no luck.

button1.loadMovie("ex1.swf");
createEmptyMovieClip("container", 2);
container.loadMovie("ex_1.swf");
container.enabled = true;
container._x =200
container._y = 50;

**Error** Scene=Scene 1, layer=nav, frame=1:Line 2: Statement must appear within on/onClipEvent handler
button1.loadMovie("ex1.swf");

**Error** Scene=Scene 1, layer=nav, frame=1:Line 3: Statement must appear within on/onClipEvent handler
createEmptyMovieClip("container", 2);

**Error** Scene=Scene 1, layer=nav, frame=1:Line 4: Statement must appear within on/onClipEvent handler
container.loadMovie("ex_1.swf");

**Error** Scene=Scene 1, layer=nav, frame=1:Line 5: Statement must appear within on/onClipEvent handler
container.enabled = true;

**Error** Scene=Scene 1, layer=nav, frame=1:Line 6: Statement must appear within on/onClipEvent handler
container._x =200

**Error** Scene=Scene 1, layer=nav, frame=1:Line 7: Statement must appear within on/onClipEvent handler
container._y = 50;

Total ActionScript Errors: 6 Reported Errors: 6

I know it says technical user in my profile but that is wrong for sure...
 
Kenneth,

Thank you very much!!!
I guess if I could read I'd get things a lot quicker.

I am not sure how to unload movie1 when I press the movie 2 button and where that code should go?

// Main timeline
// Create clip
this.createEmptyMovieClip("button1", 2);
//Add Text
this.button1.createTextField("submit_txt", 1, 0, 0, 50, 20);
this.button1.submit_txt.text = "Movie #1";
//define Button
this.button1.onRelease = function() {
container = this._parent.createEmptyMovieClip("container", 25);
container.loadMovie("ex_1.swf");
container._x = 200;
container._y = 50;
};

// Main timeline
// Create clip
this.createEmptyMovieClip("button2", 2);
//Add Text
this.button1.createTextField("submit_txt", 1, 0, 0, 50, 20);
this.button1.submit_txt.text = "Movie #2";
//define Button
this.button1.onRelease = function() {
container = this._parent.createEmptyMovieClip("container", 25);
container.loadMovie("ex_2.swf");
container._x = 200;
container._y = 50;
};
 
If you load a new movie into a MovieClip, the existing contents will be automatically replaced. Therefore there's no need to unload it.

You can certainly repeat the same script again and again to create buttons to load different movies, but you can also do it like this:

[tt]// Main timeline
// Create a container
this.createEmptyMovieClip("container", 1000);
with (container) {
_x = 200;
_y = 50;
}
// Create and define buttons
for (var i = 1; i<=2; i++) {
var buttonMC = this.createEmptyMovieClip("button"+i, 1+i);
buttonMC._x = 100*(i-1);
buttonMC.id = i;
buttonMC.createTextField("submit_txt", 1, 0, 0, 50, 20);
buttonMC.submit_txt.text = "Movie #"+i;
buttonMC.onRelease = function() {
this._parent.container.loadMovie("ex_"+this.id+".swf");
};
}
//
stop();
//[/tt]

With this approach, you can create 100 buttons by just changing one number in the script. Easier than copy, paste, and tweaking the script 100 times!

Kenneth Kawamoto
 
OH MY GOD --- THIS IS JUST UNREAL.

I hope I can learn ActionScript to the point where I can write such code.

Thank you again.

Now I have to figure out exactly what you did.

Have a wonderful Day
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top