all groups > flash actionscript > june 2005 >
You're in the

flash actionscript

group:

button rollovers over movie clips


button rollovers over movie clips dchan NO[at]SPAM cccis.com
6/19/2005 9:41:19 PM
flash actionscript: I've just learned to use createEmptyMovieClip and loadMovie. Consequently, I
also experienced my first use of depth and it's messing with my layout.

All the buttons that load their respective movie clips have a rollover that is
supposed to appear above the movie clip. But now that a depth has been assigned
to the empty movie clip, all the buttons' rollovers are under all the clips
and, therefore, hidden from view. How do I assign a depth to the buttons or
their rollovers so they appear above the movie clip? Or, is there some other
method to achive this goal?
Re: button rollovers over movie clips kglad
6/19/2005 10:23:23 PM
Re: button rollovers over movie clips dchan NO[at]SPAM cccis.com
6/19/2005 10:37:56 PM
I tried that but the buttons simply cycle through their up, over, down, hit
frames and don't behave like buttons anymore. Or, are you suggesting that I
create single-frame movie clips with a button in each so the buttons can be
tracked as buttons, but the instance can be organized as as a movie clip?
Re: button rollovers over movie clips mandingo
6/19/2005 11:02:39 PM
The issue here is that any instance created at authortime (your button
instances) will always appear at a depth lower than any instance created at
runtime (your loadMovie events).

What you can do is consider your layout a little so that the new loaded clip
loads into a clip that is positioned (change the _x and _y) so as not to
obscure the buttons, or alternately, create the holder clip for your loader
area dynamically and then dynamically attach the instances of your buttons at a
higher depth than the empty holder clip.

cheers,
Re: button rollovers over movie clips kglad
6/19/2005 11:09:28 PM
if you created a movieclip button that doesn't act like a button, it's because
of an author-error. from your statement about your movieclip button cycling
through its up, over etc, it sounds like you failed to attach a stop() to the
first frame ("up") of your movieclip button.
Re: button rollovers over movie clips mandingo
6/19/2005 11:21:40 PM
kglad, from an earlier post, this project has 22 buttons on stage at the
beginning and the requester wanted to know how to load a movie and swap a movie
depending on which button was pressed. Eventually, they have winded up using
createEmptyMovieClip and loadMovie() but I think originally all the loaded
clips were just other movieClips not .SWF's but the requestor was unable to
find enough documentation to suggest a better route to achieve what they wanted.

the code on the original button events was basically on(rollOver){
btn1.gotoAndStop(1);btn2.gotoAndStop(1);btnN.gotoAndStop(1);} to make sure all
the other buttons were off.

I think each button was a 5 frame clip to do a rollOver transition and I would
be guessing that there may now be a path problem if he has substantially
changed from the original layout.
Re: button rollovers over movie clips dchan NO[at]SPAM cccis.com
6/19/2005 11:49:05 PM
First off, thanks to everyone who's been gracious with their suggestions and
help on my ordeal.

kglad, thanks for noting the lack of a stop. After adding it to frame 1, the
buttons behaved again. But when I appled swapDepths to the movie clip that
holds these buttons and the buttons stopped working--the rollovers don't play
and clicking doesn't attach the respective movie. However, the hand cursor for
buttons does appear.

I used the following script on frame 1 to define the movie clip frame that
holds the buttons:

buttons_frame.onRollover = function() {
this.swapDepths(2);
}

The depth for the empty movie clip frame for the associated movie clips is
zero.

As I mentioned, I'm just begun to use and understand depths, so the syntax and
or the script's placement is probably wrong.

The simple arrangement I hand in mind is far more difficult to code than my
meager skills allow. I will try a little longer, but if I don't figure out or
find a solution by early tomorrow, I will take mandingo's suggestion and
reconsider my layout, perhaps putting the rollovers elsewhere.
Re: button rollovers over movie clips mandingo
6/19/2005 11:53:43 PM
hey dchan,

It is hard to get 22 buttons on a screen... how aer you doing that? in a
vertical line down the side? or horizontally in a bar across the top in 2
lines?

if it were me, I would store your buttonNames in an array...also store the
movieClips to load...

then create a loop to place your buttons and assign the clip to load on the
onPress event handler inside the loop.

you can then create a variable to keep track of the active button and onPress
of another instance, you only need to tell that other button to go back to the
Up state... not all instances as only one is down...

try this... create moveiClip button instance and call it "myButtonInstance"
and set the linkage identifier to the same... inside the clip add a textField
(dynamic) and call it "btnName"

on the movieClip add this code:

this.btnName.text = this.buttonName;
this.onRollOver = function(){
this.play();
}
this.onRollOut = this.onReleaseOutside = function(){
this.gotoAndStop(1);
}
this.onRelease = function(){
trace("this clip was the active button: " + this._parent.activeButton);
this._parent.activeButton.gotoAndStop(1);
this._parent.activeButton = this;
trace("this clip is now the active button: " + this._parent.activeButton);
this.gotoAndStop("down");
trace("about to load " + this.clip + " into the loader " +
this._parent.loaderClip);
this._parent.loaderClip.attachMovie(this.clip,this.clip,1);
}

now on the main timeline add this code to create the buttons:

buttonNames = new Array("display 1980","display 1981","display 1982","display
1983","display 1984","display 1985","display 1986",
"display 1987","display 1988","display 1989","display 1990","display
1991","display 1992","display 1993",
"display 1994","display 1995","display 1996","display 1997","display
1998","display 1999","display 2000",
"display 2001");
clipsToLoad = new
Array("mc80","mc81","mc82","mc83","mc84","mc85","mc86","mc87","mc88","mc89","mc9
0","mc91","mc92","mc93","mc94",
"mc95","mc96","mc97","mc98","mc99","mc00","mc01");

for(var k=0; k<buttonNames.length; k++){
/* attach the buttons - this will do it vertically down the left
pass into the button two parameters, the clip to load and the text to
display*/
this.attachMovie("myButtonInstance","button_"+k,k+1,{_x:5,_y:
10+(20*k),clip:clipsToLoad[k],buttonName:buttonNames[k]});
}
this.createEmptyMovieClip("loaderClip",0);
this.loaderClip._x = 75; // offset the load area by whatever you need
this.loaderClip._y = 100;

---------------------------------

change the clips that need to load to match what you need... and test that...
it should get you started at least.

cheers
Re: button rollovers over movie clips kglad
6/20/2005 12:48:42 AM
there's nothing about swapDepths() that would cause a problem with the
remainder of your button handler code. however, when you convert from a button
to a movieclip, paths to objects change. code that worked with a true button
may break when that button is converted into a movieclip. for example, with a
button that's on the _root timeline you can control a movieclip (say mc1)
that's on the _root timeline with:

btn1.onPress=function(){
mc1.loadMovie(whatever);
}

whereas with a movieclip button, mc1 will be undefined because it's not a
child of btn1. you need to use:

btn1.onPress=function(){
_root.mc1.loadMovie(whatever);
}


Re: button rollovers over movie clips dchan NO[at]SPAM cccis.com
6/20/2005 10:30:12 PM
mandingo: I have the 22 buttons set up both ways--across on one variation and
down on another. The ones that go across are little buttons--only 20 x 10 px
each--arranged in three rows of eight buttons, so the first and second rows
have eight buttons each and the third row has six. They reside in a space
that's only 127 px wide on the right side of the stage. Each rollover appears
to the left of this group, and clicking on any button brings up the display
that fills the whole left side of the stage, under the rollover (per the plan).

The other variation uses larger buttons (60 x 20 px) and are arranged in a
single column from top to bottom.Clicking a button yields a display that covers
the right half of the site's page.

I'm leaving the rollovers-over-movie-clip conundrum for now. I've submitted my
designs for review and it's wait-and-see time. If the criteria favors the one
with the covered rollovers, then I'll pick up this research where I left off.
If the criteria favors instead one of the other designs (they don't have
rollovers), then I won't bother with this anymore until the next project that
wants them.
AddThis Social Bookmark Button