PDA

View Full Version : starting and stopping external .swf playhead


notaflasher
03-12-2007, 04:41 AM
I'm trying to create a rollOver effect where the mouse's position will fade in a transparent picture below it. If you move the mouse away, the picture will fade out and another picture will fade in.

I tried loading an external .swf on rollOver which had the image fading in from 0 - 100 alpha and then loading another .swf on rollOut which had the same image fading out from 100 - 0. It works fine except that when you rollOut, the first .swf vanishes for a second before the second .swf appears. This creates a blank spot and makes the image flash.

I then tried merging both files into one .swf. Its timeline has it fading in from 0 to 100 and then back to 0 with a stop(); frame in between the tweens. I thought I might be able to play the movie from the beginning on rollOver, have it stop there, and then start it again on rollOut.

If there is a better way to do this, I'm all for it. I've picked pieces of code that I've seen here and gotten it to work other than the flash between rollOver and rollOut. But if I have unecessary code, then I'll get rid of it. The code below is only to get one image animated. All I really want to accomplish at this point is getting one image to animate on rollOver/rollOut.

--main timeline--
var loadListener:Object = new Object();
var mcLoader:MovieClipLoader = new MovieClipLoader();
var mc11:String = "over11.swf";

--on button--
on (rollOver) {
loadListener.onLoadInit = function () {
row1col1_mc.gotoAndPlay(2); //frame 1 has a stop(); to keep the movie from running on its own
}
mcLoader.addListener(loadListener);
mcLoader.loadClip(mc11, row1col1_mc);
}
on (rollOut) {
//I'll just leave this section blank because I have no idea what to put here
}

notaflasher
03-12-2007, 05:00 AM
Wow, that was quick (and lucky). I've got it working now. I'm not sure if my code is good or not, so I guess I'm now looking for some advice on how to make it better. Here's what I've got so far.

--main timeline--
var loadListener:Object = new Object();
var mc11Loader:MovieClipLoader = new MovieClipLoader();
var mc21Loader:MovieClipLoader = new MovieClipLoader();
var mc31Loader:MovieClipLoader = new MovieClipLoader();
var mc11:String = "over11.swf"; //the numbers relate to tile position by row
var mc21:String = "over21.swf"; //and column ("21" is row 2, column 1)
var mc31:String = "over31.swf"; //eventually there will be 9 animated images

--on button--
on (rollOver) {
loadListener.onLoadInit = function () {
row1col1_mc.gotoAndPlay(2);
}
mc11Loader.addListener(loadListener);
mc11Loader.loadClip(mc11, row1col1_mc);
}
on (rollOut) {
row1col1_mc.gotoAndPlay(7);
}

WhidbeyTomas
03-12-2007, 10:14 PM
I am a little unsure why you are using the listener. I can see it if the image is a very large one and your user has dial-up. But in that case, I would just keep my images small (vector).

One possible improvement is to do away with using the Flash button functionality. If you make your visual for the button a movie clip, you can place your code for this on the main timeline, in a function, like this:


myButtonMC.onRollOver=function()}
loadListener.onLoadInit = function () {
row1col1_mc.play();
}
}


Another suggestion is minor: label your target frames, if you must use a "gotoAndPlay("fade")"

In your case your first gotoAnd.. can be replaced with a simple play(); since that is all you need.

notaflasher
03-13-2007, 05:44 PM
I am a little unsure why you are using the listener. I can see it if the image is a very large one and your user has dial-up. But in that case, I would just keep my images small (vector).

One possible improvement is to do away with using the Flash button functionality. If you make your visual for the button a movie clip, you can place your code for this on the main timeline, in a function, like this:


myButtonMC.onRollOver=function()}
loadListener.onLoadInit = function () {
row1col1_mc.play();
}
}


Another suggestion is minor: label your target frames, if you must use a "gotoAndPlay("fade")"

In your case your first gotoAnd.. can be replaced with a simple play(); since that is all you need.

Thomas,

Thanks for the response. In all honesty, I'm not sure why I'm using the listener as well. I just grabbed code from threads I've seen here and got it to work. But like I said, I'm sure there is a better way to do it.

I'm trying to implement your suggestions but not having much luck. The first set of curly braces are facing the wrong way, but that was an easy fix. After that, things got a little dicey. How do I make a movie clip and give it an instance name of myButtonMC without putting it somewhere on the stage?

I added a stop(); to a blank frame 1 on the movie clip, added the movie clip to its own layer on the main timeline, and changed row1col1_mc.play(); to row1col1_mc.play(2); thinking that the image would be on the stage at frame 1 and the rollover would start its playhead at frame 2. Nothing happens. I'll keep trying. :confused:

notaflasher
03-13-2007, 06:03 PM
You know, what might make more sense here is to "pretend" that I don't know what the heck I'm doing and just for fun, scrap everything I've done so far. What would be the most efficient way to accomplish the following...

Consider the smilies as images placed on the stage, but they are currently invisible.

:confused: :eek: :mad:

When the user mouses over the space where a smily is, it fades in to view. When the user moves the mouse off of one smily and over the space occupied by another, the other fades out and the one under the mouse now fades in to view.

This is eventually going to be incorporated into a .swf that will be loaded externally into my main .swf's timeline. (crikey, I hope I said that right).

WhidbeyTomas
03-13-2007, 11:27 PM
This is a pretty simple thing to implement. I spent a lot of time creating a list of steps and then lost them all because I had to log in again (@#%#).

But the idea is to create image symbols inside MCs that are set to 0% alpha and make the MCs buttons that will play on mouseOver. I will attach an FLA that shows how I do this.

Let me know if this is not what you seek, or if you have questions.

That Whidbey guy.

notaflasher
03-14-2007, 03:11 AM
Thanks again for your help, Thomas. That effect isn't quite what I'm after. I attached (or at least attempted to) the main .swf and external .swf's in a zip file so you can see the effect I want. It works, but I would rather learn to do this the right way instead of just finding a clunky solution.

21663

WhidbeyTomas
03-14-2007, 08:03 PM
I think you are going to have to change your name. What you have is very nearly the same as what I have. By loading the images from external files you are wisely taxing the client only when needed (especially useful for dialup).

My alternative loads everything at once. This might be an unnessesary burden if it loads items the user might never need or if in loading as needed, the "tax" is not obvious.

Except for the seemingly unnecessary listener, there is nothing clunky about your method. It works efficiently, and that is all I care about in my product.

Thomas

notaflasher
03-15-2007, 04:03 AM
I think you are going to have to change your name. What you have is very nearly the same as what I have. By loading the images from external files you are wisely taxing the client only when needed (especially useful for dialup).

My alternative loads everything at once. This might be an unnessesary burden if it loads items the user might never need or if in loading as needed, the "tax" is not obvious.

Except for the seemingly unnecessary listener, there is nothing clunky about your method. It works efficiently, and that is all I care about in my product.

Thomas

Rox! I'm glad to hear that I was on the right path. I'm not going to change my name just yet, however. I have quite a ways to go. But for now I guess I'm going to push ahead with the code I've got in place, except for the listener as it seems unnecessary. Thanks again Thomas. ;)