Link to home
Start Free TrialLog in
Avatar of John Carney
John CarneyFlag for United States of America

asked on

Using action script to swap bitmaps in a Movie Clip

On the main timeline I have an MC called "bkgrnd", which in its default state consists of a bitmap named "bkgrnd1_green".  There are six buttons on the main Timeline, which are instances of a movie clip called "btn_1".
I would like to modify the script so that when the user clicks on the instance of "btn_1" named "btn_Res", then upon release the bitmap "bkgrnd1_green"  (inside MC "bkgrnd") is replaced by bitmap "bkgrnd2_brown"

Attached is a snippet of the code that controls the actions of the six instances of "btn_1":
How can I supplement each 2 line snippet to swap the bitmaps in MC "bkgrnd"? ("btn_Comml" might switch to bitmap "bkgrnd3_blue").

Thanks!
John

btn_Res.onPress = function(){
      gotoAndStop(27);}
btn_Comml.onPress = function(){
      gotoAndStop(28);}

Open in new window

Avatar of blue-genie
blue-genie
Flag of South Africa image

is your bitmap inside a frame or are you attaching it at run time. if the latter are you attaching from the library or from a folder somewhere?
Avatar of John Carney

ASKER

It's inside a frame, and I am attaching it from the library. But, after I get the answer for those criteria, I would love to learn how to do it the other way as well, which I imagine is more professional.

Thanks,
john
Avatar of Antonio Estrada
First off; each one of them would need a linkage identifier (On the library, right click -> properties -> check "Export for ActionScript")... now afterwards, this is the code you'd need:

<code snippet>

-V
On btn_Res (after your on(rollOver) and on(rollOut) events:
 
on(release) {
	_parent.green.attachMovie("bkgrnd2_brown","brown",_parent.green.getDepth()+1);
}
 
On btn_Comml (same, after on(rollOver) and on(rollOut):
 
on(press) {
	_parent.green.attachMovie("bkgrnd3_blue","blue",_parent.green.getDepth()+1);
}
 
etc...
 
And on btnHome:
 
 
on(press) {
	_parent.green.attachMovie("bkgrnd1_green","green",_parent.green.getDepth()+1);
}

Open in new window

Oh, and if you're now using the object.Event syntax, it should be:

<code snippet>

Also, pay no mind to my on(press) and on(release) mix, I just copied it too fast :P

-V
btnRes.onPress = function() {
        green.attachMovie("bkgrnd2_brown","brown",green.getDepth()+1);
}
 
btn_Comml.onPress = function() {
        green.attachMovie("bkgrnd3_blue","blue",green.getDepth()+1);
}
 
btnHome.onPress = function() {
        green.attachMovie("bkgrnd1_green","green",green.getDepth()+1);
}

Open in new window

Hi Vulturous,

I couldn't get yours to work, but as I played around with it, I came up with what seems to be the perfect solution: If I place brown on the timeline under green (my default background, then all I need is this code:

btn_1.onPress = function() {
green._visible = false      
brown._visible = true}
 
btn_2.onPress = function() {
green._visible = true
brown._visible = false}

I'm definitely going to award you the points for getting me started, but in the meantime, could you tell me  more about attachMovie. If my movie clip is named "bkgrnd_Brown", couldn't i just say "attachMovie("bkgrnd_Brown") ? I tried that but I got an error. What would the proper syntax be?   How else would I use attachMovie?

John
ASKER CERTIFIED SOLUTION
Avatar of Antonio Estrada
Antonio Estrada
Flag of Mexico image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks, Vulturous. Yes this helps a lot. If I can ask you one more  question: when the new movie is atached, are all other contending movies gone from the stage, so that there is no need to detach the previous movie?

Thanks,

John
The other movies will be gone if they're placed in the same depth level.

Suppose you do this:

_root.attachMovie("aSquare","mySquare",20);

And later you do this:

_root.attachMovie("aCircle","myCircle",20);

If you do that then no, you wouldn't need to unload a movie, however if you're using different depth levels then you'll have to use unloadMovie(); or removeMovieClip();

Good Luck! :)

-V