Solved

Using action script to swap bitmaps in a Movie Clip

Posted on 2007-11-25
8
1,294 Views
Last Modified: 2008-02-01
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

0
Comment
Question by:gabrielPennyback
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 39

Expert Comment

by:blue-genie
ID: 20348791
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?
0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 20351856
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
0
 
LVL 18

Expert Comment

by:Antonio Estrada
ID: 20362781
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

0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 18

Expert Comment

by:Antonio Estrada
ID: 20362793
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

0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 20418497
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
0
 
LVL 18

Accepted Solution

by:
Antonio Estrada earned 500 total points
ID: 20423193
attachMovie is a really useful method that avoids having a lot of objects present in the stage at all times. It can get any MovieClip from within your library and place it on stage when some code triggers it.

It's syntax is this: MovieContainer.attachMovie("MovieClipLinkage","MovieClipName",depth);

Where "MovieContainer" is the name of the instance of a MovieClip present in the stage which will hold the newly attached movie. You can safely use the properties "_root" or "this".
"MovieClipLinkage" is the name of the linkage identifier as it appears on the library of your movie. It's what attachMovie looks up for attaching a MovieClip. It has to go with the quotation marks in order for it to be found.
"MovieClipName" is the name you'll give to the newly attached movie, you can then access to that MovieClip by refering to it's Container and the MovieClip name.

Let's say you typed this:
_root.attachMovie("aSquare","mySquare",_root.getNextHighestDepth());

You can later use the mySquare MovieClip by typing "_root.mySquare", as "mySquare" after being attached is a part of the MovieContainer, in this case; _root.

"depth" refers to the layer it will be using. If you use the same depth; the new MovieClip will erase whatever there was before. Normally you'd want to attach a MovieClip and place it on top of most things, so instead of depth, you can type this.getNextHighestDepth()

Hope that helps you.

-V
0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 20433024
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
0
 
LVL 18

Expert Comment

by:Antonio Estrada
ID: 20433185
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
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question