Jump to content
Search Community

LoaderMax

chefkeifer test
Moderator Tag

Recommended Posts

Ok i finally dived into the LoaderMax per you question to me in the Tweening forum. The reason I have not gotten into it is that i do not fully understand it yet. Working on. I will say after doing some reading i was able to get something to work on the first try. That never happens for me.

 

anyway my question is how do i incorporate buttons and for jsut a simple fade in and out of external swf's. I have six buttons that i have in an array that i tween for the over and out states but for the click function is where i am clueless. I just want to be able to click on that button and that specific swf will come to the stage and the one that is already on the stage will just tween out. make sense...

 

here is the code to get the default(home page) external swf to appear whne first coming to the site

 

var queue:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});  
queue.append( new SWFLoader("fr_palmetto.swf", {name:"fr_palmetto", estimatedBytes:3000, container:this,x:0,y:315,alpha:0, autoPlay:false}) );  
LoaderMax.prioritize("btn1");   
queue.load();  
//*****====================================================******//
function progressHandler(event:LoaderEvent):void {  
trace("progress: " + event.target.progress);
loadMC.scaleX = event.target.progress;
}  
//*****====================================================******//  
function completeHandler(event:LoaderEvent):void {  
var image:ContentDisplay = LoaderMax.getContent("fr_palmetto");  
	TweenLite.to(image, 1, {alpha:1});  
	trace(event.target + " is complete!"); 
	loadMC.visible = false;
}  
//*****====================================================******//
function errorHandler(event:LoaderEvent):void {  
trace("error occured with " + event.target + ": " + event.text);  
} 

Link to comment
Share on other sites

It depends on how you built your file. Here's an example:

 

var curLoader:SWFLoader;

section1Button.addEventListener(MouseEvent.CLICK, clickHandler);
section2Button.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
   if (curLoader != null) {
       TweenMax.to(curLoader.content, 0.5, {autoAlpha:0});
   }
   if (event.currentTarget == section1Button) {
       curLoader = section1Loader;
   } else if (event.currentTarget == section2Button) {
       curLoader = section2Loader;
   }
   addChild(curLoader.content); //brings to the top
   TweenMax.to(curLoader.content, 0.5, {autoAlpha:1});
}

 

That assumes that you've already put the loaders into a LoaderMax queue and loaded them. It would also be a good idea to set the SWFLoader's "alpha" special property to 0 so that they fade in from 0.

Link to comment
Share on other sites

my buttons are done this way.

 

var activeTween:TimelineLite;
activeTween = null;
//*****==========================*****\\
for (var j:int = 0; j < btns.length; j++) {
  btns[j].buttonMode = true;
  btns[j].addEventListener(MouseEvent.ROLL_OVER, over);
  btns[j].addEventListener(MouseEvent.ROLL_OUT, out);
  btns[j].addEventListener(MouseEvent.CLICK, clickHandler);
  activeTween = new TimelineLite({paused:true});
  activeTween.insert(TweenMax.to(btns[j], .5, {glowFilter:{color:0xffffff, alpha:1, blurX:15, blurY:15, inner:true}}));
  activeTween.insert(TweenMax.to(btns[j], .5, {dropShadowFilter:{color:0x000000, alpha:1, blurX:5, blurY:5, distance:5}}));
  btns[j].tween = activeTween;
}

 

so i guess i get confused with the multiple buttons..that would be a lot of if statements with six or eight buttons in the clickHandler function...

Link to comment
Share on other sites

Of course - I didn't literally mean that you'd list everything out in the if/else statement. I was merely trying to demonstrate a basic concept and keep things simple.

 

You could do something like:

 

var activeTween:TimelineLite;
var queue:LoaderMax = new LoaderMax();
var swfs:Array = ["child1.swf", "child2.swf", ...];

for (var j:int = 0; j    btns[j].buttonMode = true;
  btns[j].addEventListener(MouseEvent.ROLL_OVER, over);
  btns[j].addEventListener(MouseEvent.ROLL_OUT, out);
  btns[j].addEventListener(MouseEvent.CLICK, clickHandler);
  activeTween = new TimelineLite({paused:true});
  activeTween.insert(TweenMax.to(btns[j], .5, {glowFilter:{color:0xffffff, alpha:1, blurX:15, blurY:15, inner:true}}));
  activeTween.insert(TweenMax.to(btns[j], .5, {dropShadowFilter:{color:0x000000, alpha:1, blurX:5, blurY:5, distance:5}}));
  btns[j].tween = activeTween;
  btns[j].loader = new SWFLoader(swfs[j], {alpha:0});
  queue.append( btns[j].loader );
}
queue.load();

var curLoader:SWFLoader;
function clickHandler(event:MouseEvent):void {
   if (curLoader != null) {
       TweenMax.to(curLoader.content, 0.5, {autoAlpha:0});
   }
   curLoader = event.currentTarget.loader;
   addChild(curLoader.content);
   TweenMax.to(curLoader.content, 0.5, {autoAlpha:1});
}

Link to comment
Share on other sites

thanks for working with me on this..you have always been there for me...I have tried to incorporate you code into what i have and see to be headed in the right direction but i am getting this error

 

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock.loading.core::LoaderItem/_setRequestURL()
at com.greensock.loading.core::LoaderItem()
at com.greensock.loading.core::DisplayObjectLoader()
at com.greensock.loading::SWFLoader()
at main_test_fla::MainTimeline/frame1()

 

and this is my code..

 

import com.greensock.*;  
import com.greensock.loading.*;  
import com.greensock.events.LoaderEvent;  
import com.greensock.loading.display.*;
import com.google.analytics.AnalyticsTracker; 
import com.google.analytics.GATracker;
//*****====================================================*****\\
var tracker:AnalyticsTracker = new GATracker( this, "UA-17893711-1", "AS3", false );
tracker.trackPageview("btn1"); tracker.trackPageview("btn2"); tracker.trackPageview("btn3");
tracker.trackPageview("btn4"); tracker.trackPageview("btn5"); tracker.trackPageview("btn6");
tracker.trackPageview("fr_palmetto"); tracker.trackPageview("fr_busco");
tracker.trackPageview("fr_broad");
//*****====================================================*****\\
var btns:Array = [btn1,btn2,btn4,btn5,btn6,fr_palmetto,fr_busco,fr_broad,facebook,gear,evtSchedule];
var swfs:Array = ["btn1.swf", "btn2.swf","btn3.swf","btn4.swf","btn5.swf","btn6.swf","fr_palmetto", "fr_busco", "fr_broad"];
//*****====================================================*****\\
fr_palmetto.btn_txt.text = "Home"
btn2.btn_txt.text = "Registration"
btn1.btn_txt.text = "Series Schedule"
btn4.btn_txt.text = "Parks"
btn5.btn_txt.text = "CMT Redneck Wedding"
btn6.btn_txt.text = "Contact"
fr_busco.btn_txt.text = "Busco Beach Highlights"
fr_broad.btn_txt.text = "Broad River Highlights"
//*****====================================================*****\\
var activeTween:TimelineLite;
var curLoader:SWFLoader;
var queue:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler}); 
LoaderMax.prioritize("fr_palmetto");
activeTween = null;
//*****==========================*****\\
for (var j:int = 0; j < btns.length; j++) {
  btns[j].buttonMode = true;
  btns[j].addEventListener(MouseEvent.ROLL_OVER, over);
  btns[j].addEventListener(MouseEvent.ROLL_OUT, out);
  btns[j].addEventListener(MouseEvent.CLICK, clickHandler);
  activeTween = new TimelineLite({paused:true});
  activeTween.insert(TweenMax.to(btns[j], .5, {glowFilter:{color:0xffffff, alpha:1, blurX:15, blurY:15, inner:true}}));
  activeTween.insert(TweenMax.to(btns[j], .5, {dropShadowFilter:{color:0x000000, alpha:1, blurX:5, blurY:5, distance:5}}));
  btns[j].tween = activeTween;
  btns[j].loader = new SWFLoader(swfs[j], {estimatedBytes:3000, container:this,x:0,y:315,alpha:0, autoPlay:false});
  queue.append( btns[j].loader );
}
//*****====================================================*****\\
queue.load();
//*****====================================================******//
function over(event:MouseEvent):void {
  activeTween = event.currentTarget.tween;
  activeTween.play();
}
//*****=====================*****\\
function out(event:MouseEvent):void {
  activeTween.reverse();
}
//*****====================================================*****\\
function progressHandler(event:LoaderEvent):void {  
trace("progress: " + event.target.progress);
}  
//*****====================================================******//  
function completeHandler(event:LoaderEvent):void {  
var image:ContentDisplay = LoaderMax.getContent("fr_palmetto");  
	TweenLite.to(image, 1, {alpha:1});  
	trace(event.target + " is complete!"); 
}  
//*****====================================================******//
function errorHandler(event:LoaderEvent):void {  
trace("error occured with " + event.target + ": " + event.text);  
}
//*****====================================================******//
function clickHandler(event:MouseEvent):void {
   if (curLoader != null) {
       TweenMax.to(curLoader.content, 0.5, {autoAlpha:0});
   }
   curLoader = event.currentTarget.loader;
   addChild(curLoader.content);
   TweenMax.to(curLoader.content, 0.5, {autoAlpha:1});
}

Link to comment
Share on other sites

good eye..i forgot to take those two out of there...that will be another thread since they are outside URL's....anyway i took them away and all worked just fine but and the buttons navigated between swf but only once..meaning i was able to click on the button go to another button but if i went back to that button the swf would not come back up...

 

these are the errrors i am getting..i am assuming the google analytics errors are on the child swf since i tried removing all google stuff and still go the error..

 

progress: 0.40741776857705914
progress: 0.8148355371541183
progress: 0.860752096582679
progress: 0.7109514134060105
progress: 0.9278920716130359
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.google.analytics.core::IdleTimer()
at com.google.analytics::GATracker/_trackerFactory()
at com.google.analytics::GATracker/_factory()
at com.google.analytics::GATracker()
at btn2_fla::MainTimeline/frame1()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.google.analytics.core::IdleTimer()
at com.google.analytics::GATracker/_trackerFactory()
at com.google.analytics::GATracker/_factory()
at com.google.analytics::GATracker()
at btn1_fla::MainTimeline/frame1()
progress: 0.932391411175509
progress: 0.9372671478508771
progress: 0.6330214283280907
progress: 0.7570566614808675
progress: 0.8810918946336441
progress: 0.9669831139778108
progress: 0.7833733089629212
progress: 0.8724331229233623
progress: 0.9614929368838034
progress: 0.9775094616539719
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.google.analytics.core::IdleTimer()
at com.google.analytics::GATracker/_trackerFactory()
at com.google.analytics::GATracker/_factory()
at com.google.analytics::GATracker()
at btn4_fla::MainTimeline/frame1()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.google.analytics.core::IdleTimer()
at com.google.analytics::GATracker/_trackerFactory()
at com.google.analytics::GATracker/_factory()
at com.google.analytics::GATracker()
at btn3_fla::MainTimeline/frame1()
progress: 0.9803700407004002
progress: 0.9836926610179856
progress: 0.9878030510113966
progress: 0.8903181875132783
progress: 0.9617194437029815
progress: 0.9914136764521629
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.google.analytics.core::IdleTimer()
at com.google.analytics::GATracker/_trackerFactory()
at com.google.analytics::GATracker/_factory()
at com.google.analytics::GATracker()
at btn6_fla::MainTimeline/frame1()
progress: 0.9931568711833568
progress: 0.9934630197580228
progress: 0.9967207918194687
Loading error on SWFLoader 'loader6' (fr_palmetto): Error #2035: URL Not Found. URL: file:///C|/Users/keith/Documents/Websites/ATV%20Redneck%20Nationals/fr_palmetto
error occured with SWFLoader 'loader6' (fr_palmetto): SWFLoader 'loader6' (fr_palmetto) > Error #2035: URL Not Found. URL: file:///C|/Users/keith/Documents/Websites/ATV%20Redneck%20Nationals/fr_palmetto
progress: 1
LoaderMax 'mainQueue' is complete!
Loading error on SWFLoader 'loader7' (fr_busco): Error #2035: URL Not Found. URL: file:///C|/Users/keith/Documents/Websites/ATV%20Redneck%20Nationals/fr_busco
error occured with SWFLoader 'loader7' (fr_busco): SWFLoader 'loader7' (fr_busco) > Error #2035: URL Not Found. URL: file:///C|/Users/keith/Documents/Websites/ATV%20Redneck%20Nationals/fr_busco

Link to comment
Share on other sites

Hey Jack,

I fixed the url issue, still not sure why the google crap keeps showing up. I will get to that later..

 

but here is the output i am receiving and i also noticed when clicking the buttons the correct swf is not coming to the stage. is there a specific order that i need to have each of the arrays in or should it matter what the instance name of the button. Not sure i said that right. Should in the clickHandler be what is clicked the event.currentTarget or something that sorts.

 

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at com.greensock::TweenLite/init()
at com.greensock::TweenLite/renderTime()
at com.greensock.core::SimpleTimeline/renderTime()
at com.greensock::TweenLite$/updateAll()

and that error repeats itself about 20 times.

 

also in the default swf does not show up at the beginning..the one in the completeHandler. I can hear the video that is playing but you cant see anything that is on that swf

Link to comment
Share on other sites

Could you isolate the problem in an FLA that publishes cleanly? I tried publishing the FLA you posted and got a ton of compile errors about undefined properties and such (which have nothing to do with LoaderMax). I just have very limited time, so I can't go through and clean up all the non-GreenSock-related code.

 

As far as things needing to be in the right order, yes, your code relies on the btns and swfs arrays being synced in terms of their indexes. Like the first button in the array will be associated with the first swf url in the swfs array, and so on. Frankly if I were building it, I'd probably do it a bit different, like create a class that associates the data instead of relying on arrays that have a certain order in their elements, but I didn't want to make this too complicated or restructure your code too much.

 

I'd encourage you to push through this a bit because once you get the hang of LoaderMax, I think you'll find that it can be a huge help and actually quite intuitive.

 

As far as the error you were getting with TweenLite, that has to do with the fact that you're trying to tween a null object. So one of the targets of your tweens is null which points to something else in your code being off (you obviously shouldn't tween a null object). Again, since you didn't include any of the assets that are being loaded, when I published all of the loaders failed. It'd be super swell if you'd post a folder that has everything necessary to just open the FLA and publish to see the problem reproduced. I'm sure we can get it figured out.

Link to comment
Share on other sites

ok...i have finally pretty much started over as far as getting things to work properly. I have attached a working fla with all the swf that apply to it. I am still getting that one error. i have eliminated all that google stuff...i have the buttons working properly as far as getting the proper swf to come to the stage. the default page in the completeHandler function does not come up to be the actual first page to come to the stage. i know your time is limited and i do appreciate it.

Link to comment
Share on other sites

The problem is that on line 55 you do this:

 

var image:ContentDisplay = LoaderMax.getContent("fr_palmetto"); 

 

But there is no loader named "fr_palmetto" nor is there one with a URL matching that, so image ends up being null. You tried tweening that, and you cannot tween a null object. I believe what you meant to do was put a ".swf" on the end of that, like:

 

var image:ContentDisplay = LoaderMax.getContent("fr_palmetto.swf"); 

 

That works fine. :)

Link to comment
Share on other sites

once again its something so simple that i was overlooking...

 

just for future reference...what exaclty does null mean?

 

and

 

if i get that error again on my other projects what is the best way to find where that error is coming from?

 

thanks again for you help...i will have to apply this to my other pages so that the buttons work within the child swf's...i am sure its that darn google analytics...

Link to comment
Share on other sites

null basically means nothing...undefined...nada...zilch. Like:

 

var myQueue:LoaderMax;
trace(myQueue); //traces null - you never set myQueue to anything.

 

As far as finding where the null reference is that's throwing errors, look at the errors that Flash spits out and see which method it started in. You can add a trace() call above the tween to see if the target is null, like:

trace(myObject);
TweenLite.to(myObject, 1, {x:100});

 

Definitely get familiar with trace() - it can be a big help.

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...