Jump to content
Search Community

Loading and unloading external SWF files using a MouseEvent

reveldevil test
Moderator Tag

Recommended Posts

Hello:

 

I'm new to your Greensock classes and somewhat new to ActionScript 3.0.

 

What I'm trying to achieve with the use of your Loadermax class is the ability to have my mouse rollover an invisible hot spot on the stage and load (dissolve in) an external SWF file. I am able to get the loading process to work and achieve the fade in I desire, but for the life of me I'm unable to get the external SWF file to unload (fade out) no matter what I try. Additionally I am also running into the issue that whenever I do rollover the hotspot, a new instance of the external SWF loads on top of the other one I'm trying to make disappear. Below is the code with the working part of the product (no errors). I'm looking for suggestions to how I might get the external SWF to fade out and unload when the users mouse moves away from the invisible hot spot. I thank you for your time and help.

 

import com.greensock.*;

import com.greensock.loading.*;

import com.greensock.easing.*;

import com.greensock.events.LoaderEvent;

 

hotspot.addEventListener(MouseEvent.MOUSE_OVER, navOver);

hotspot.addEventListener(MouseEvent.MOUSE_OUT, navOut);

hotspot.alpha = 0;

 

function navOver(e:MouseEvent)

{

var loader:SWFLoader = new SWFLoader("toyota_overlay.swf",{container:this,x:178,y:377,alpha:0, name:"swf1", onComplete:completeHandler});

addChild(loader.content);

loader.load();

 

function completeHandler(e:LoaderEvent):void

{

TweenLite.to(e.target.content, 1, {alpha:1});

var mcTemp:MovieClip = loader.rawContent;

mcTemp.testing();

}

}

 

function navOut(e:MouseEvent):void

{

trace("Release");

}

Link to comment
Share on other sites

I'm not a SWFLoader expert, but I got the following to work:

import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.easing.*;
import com.greensock.events.LoaderEvent;

hotspot.addEventListener(MouseEvent.MOUSE_OVER, navOver);
hotspot.addEventListener(MouseEvent.MOUSE_OUT, navOut);
hotspot.alpha=.5;
hotspot.buttonMode=true;

var loader:SWFLoader;

trace(loader);
function navOver(e:MouseEvent) {
   //only load if the loader isn't defined
if (!loader) {
	loader=new SWFLoader("toyota_overlay.swf",{container:this,x:0,y:0,alpha:0,name:"swf1",onComplete:completeHandler});

	loader.load();
}

}

//this function was nested in navOver I moved it out
function completeHandler(e:LoaderEvent):void {
TweenLite.to(e.target.content, 1, {alpha:1});
}


function navOut(e:MouseEvent):void {

//the tween will throw error if the loader content isn't there
       //only do the tween if there is something to tween
if (loader) {
	//tween alpha to .5 so you can see the disposeLoader function remove the swf
	TweenLite.to(loader.content, 1, {alpha:.5, onComplete:disposeLoader});
}
}


function disposeLoader() {
//the loader has rawContent
trace("loader raw "  + loader.content.rawContent);
loader.dispose(true);
//the loader doesn't have rawContent
trace("loader raw " + loader.content.rawContent);
//nuke the loader
loader=null;
}



 

There is most likely a more elegant way. This seemed to work fine when testing locally.

 

Carl

Link to comment
Share on other sites

hey, this seems to work just as well and is much cleaner:


import com.greensock.*;
import com.greensock.loading.*;
import com.greensock.easing.*;
import com.greensock.events.LoaderEvent;

hotspot.addEventListener(MouseEvent.MOUSE_OVER, navOver);
hotspot.addEventListener(MouseEvent.MOUSE_OUT, navOut);
hotspot.alpha=.5;
hotspot.buttonMode=true;

var loader:SWFLoader =new SWFLoader("toyota_overlay.swf",{container:this,x:0,y:0,alpha:0,name:"swf1",onComplete:completeHandler});

trace(loader);
function navOver(e:MouseEvent) {

	loader.load();


}

//this function was nested in navOver I moved it out
function completeHandler(e:LoaderEvent):void {
TweenLite.to(e.target.content, 1, {alpha:1});
}


function navOut(e:MouseEvent):void {

	TweenLite.to(loader.content, 1, {alpha:.5, onComplete:disposeLoader});

}


function disposeLoader() {

loader.unload();

}

 

the SWFLoader is smart enough to know whether or not it's content is loaded and won't try to reload it if it is already there.

by using the unload() method in the disposeLoader function the swf gets unloaded but the SWFLoader is still hanging around knowing that it's loaded content isn't there anymore and is standing by ready to load again.

 

Carl

Link to comment
Share on other sites

Hi Carl:

 

Your code is a step in the right direction, but this design is still not working as well as it should. Here are a couple factors that I also didn't address that may be influencing its behavior.

 

1. The external overlay I am trying to fade in and out sits on top of an external video that plays at the same time.

2. The external overlay has 3 MovieClip (AS3) buttons that are coded within that overlay.

 

I'm finding the overlay to load up just fine, but then blink every 1 second as it seems to be unloading and reloading. I don't want the overlay to be timed on stage with a predetermined number, but rather hold until the mouse moves off the hot spot. Additionally I'm seeing a lag time here also from the moment I move the mouse off the hotspot to the moment it disappears. This also seems to be associated with the 1 second hold time? I've tried to remove this timer, but then the overlay doesn't appear.

 

Anymore suggestions?

 

Thanks,

 

Andrew

Link to comment
Share on other sites

it sounds like you are moving your mouse, or items in the overlay are obstructing you hotspot and triggering a MOUSE_OUT.

 

when the clip unloads your mouse is back over your overlay and it triggers the MOUSE_OVER causing the asset to reload again giving you the blink.

 

its safer to use ROLL_OVER and ROLL_OUT unless you have a reason to use MOUSE_OUT.

 

in the navOver and navOut handlers put in a trace and you will probably see these events firing often.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...