chefkeifer Posted November 16, 2009 Share Posted November 16, 2009 I am trying to tween an external swf and for some reason i keep getting this error TypeError: Error #1009: Cannot access a property or method of a null object reference. at thebarnettecompanies_fla::MainTimeline/scene() at thebarnettecompanies_fla::MainTimeline/frame1() Here is the code i have..everything looks fine to me..anyone have some suggestions of how to fix this.. //*****====================================================***** var request:URLRequest = new URLRequest("homePage.swf");//COMMERICAL RELOCATION var request1:URLRequest = new URLRequest("commercial.swf");//HOME PAGE //*****====================================================***** var contentLoader:Loader = new Loader(); //*****====================================================***** function scene(){ contentLoader.load(request) addChild(contentLoader); TweenMax.to(contentLoader,1,{x:33, y:85, alpha:1}); } scene(); //*****====================================================***** function clicked(event:MouseEvent):void{ switch(event.currentTarget.name){ case"commerical": TweenMax.to(contentLoader,1,{alpha:0, onComplete:onFinish}); function onFinish():void { contentLoader.load(request1) addChild(contentLoader); TweenMax.to(contentLoader,1, {alpha:1}); tracker.trackPageview("commercial"); } break; } } Link to comment Share on other sites More sharing options...
GreenSock Posted November 16, 2009 Share Posted November 16, 2009 This doesn't look like a tween-related problem - my guess is that in the scene() function, contentLoader is null so calling load() in it will throw that error. Try doing a trace(contentLoader) in there to find out if it's null. Also, you did import the TweenMax class, right? Link to comment Share on other sites More sharing options...
chefkeifer Posted November 16, 2009 Author Share Posted November 16, 2009 ok i got old content to fade out but the new content does not alpha in //*****====================================================***** var request:URLRequest = new URLRequest("homePage.swf");//HOMEPAGE var request1:URLRequest = new URLRequest("commercial.swf");//COMMERCIAL RELOCATION //*****====================================================***** var contentLoader:Loader = new Loader(); //*****====================================================***** function scene(){ contentLoader.load(request) addChild(contentLoader); var fadeIn:TimelineMax = new TimelineMax(); fadeIn.append(TweenMax.to(contentLoader, .1, {alpha:0})); fadeIn.append(TweenMax.to(contentLoader,.25, {x:0,y:325})); fadeIn.append(TweenMax.to(contentLoader, 5, {alpha:1})); } scene(); //*****====================================================***** function clicked(event:MouseEvent):void{ switch(event.currentTarget.name){ case"commercial": TweenMax.to(contentLoader,1,{alpha:0, onComplete:onFinish}); function onFinish():void { contentLoader.load(request1) addChild(contentLoader); TweenMax.to(contentLoader,1, {x:0, y:325,alpha:1}); //tracker.trackPageview("commercial"); } break; Link to comment Share on other sites More sharing options...
GreenSock Posted November 16, 2009 Share Posted November 16, 2009 It's virtually impossible to troubleshoot this blind - there's something else going on in your code that we can't see from the brief excerpt you posted here. Did you do the trace()? Are you waiting for the content to load before you do the fade? It doesn't look like you are. So if your fade takes 5 seconds to fade in, but your content takes 6 seconds to load, the fade would be done by the time the content actually shows up, so it would look like the fade didn't work. Link to comment Share on other sites More sharing options...
chefkeifer Posted November 16, 2009 Author Share Posted November 16, 2009 here is the code. I would attached the fla but it was too big. this has been one issue i have never been able to fix over the past year. I have had to just use no tweening in and out my content. I appreciate your help!!! import com.greensock.*; import com.greensock.plugins.*; import com.greensock.easing.*; import com.google.analytics.AnalyticsTracker; import com.google.analytics.GATracker; TweenPlugin.activate([Physics2DPlugin]); //----------------------------------------------- var tracker:AnalyticsTracker = new GATracker( this, "UA-11181582-1", "AS3", false ); //----------------------------------------------- commercial.buttonMode = true; commercial.btn_txt.text = "Commerical Relocation..." commercial.addEventListener(MouseEvent.MOUSE_OVER, over); commercial.addEventListener(MouseEvent.MOUSE_OUT, out); commercial.addEventListener(MouseEvent.CLICK, clicked); //----------------------------------------------- residential.buttonMode = true; residential.btn_txt.text = "Residential Relocation..." residential.addEventListener(MouseEvent.MOUSE_OVER, over); residential.addEventListener(MouseEvent.MOUSE_OUT, out); residential.addEventListener(MouseEvent.CLICK, clicked); //----------------------------------------------- buyFurniture.buttonMode = true; buyFurniture.btn_txt.text = "Buy Furniture..." buyFurniture.addEventListener(MouseEvent.MOUSE_OVER, over); buyFurniture.addEventListener(MouseEvent.MOUSE_OUT, out); buyFurniture.addEventListener(MouseEvent.CLICK, clicked); //----------------------------------------------- sellFurniture.buttonMode = true; sellFurniture.btn_txt.text = "Sell Furniture..." sellFurniture.addEventListener(MouseEvent.MOUSE_OVER, over); sellFurniture.addEventListener(MouseEvent.MOUSE_OUT, out); sellFurniture.addEventListener(MouseEvent.CLICK, clicked); //----------------------------------------------- fileMoving.buttonMode = true; fileMoving.btn_txt.text = "File Moving..." fileMoving.addEventListener(MouseEvent.MOUSE_OVER, over); fileMoving.addEventListener(MouseEvent.MOUSE_OUT, out); fileMoving.addEventListener(MouseEvent.CLICK, clicked); //----------------------------------------------- shredding.buttonMode = true; shredding.btn_txt.text = "Document Shredding..." shredding.addEventListener(MouseEvent.MOUSE_OVER, over); shredding.addEventListener(MouseEvent.MOUSE_OUT, out); shredding.addEventListener(MouseEvent.CLICK, clicked); //----------------------------------------------- storage.buttonMode = true; storage.btn_txt.text = "Storage Facilities..." storage.addEventListener(MouseEvent.MOUSE_OVER, over); storage.addEventListener(MouseEvent.MOUSE_OUT, out); storage.addEventListener(MouseEvent.CLICK, clicked); //----------------------------------------------- cubicle.buttonMode = true; cubicle.btn_txt.text = "Cubicle Installation..." cubicle.addEventListener(MouseEvent.MOUSE_OVER, over); cubicle.addEventListener(MouseEvent.MOUSE_OUT, out); cubicle.addEventListener(MouseEvent.CLICK, clicked); //----------------------------------------------- menu.about.addEventListener(MouseEvent.CLICK, clicked); menu.faq.addEventListener(MouseEvent.CLICK, clicked); menu.movePlanning.addEventListener(MouseEvent.CLICK, clicked); menu.moveInstructions.addEventListener(MouseEvent.CLICK, clicked); menu.contact.addEventListener(MouseEvent.CLICK, clicked); //*****====================================================***** // BUTTON OVER FUNCTION function over(event:MouseEvent){//MAIN BUTTONS var over:TimelineMax = new TimelineMax(); over.append(TweenMax.to(event.currentTarget.btn_txt, .5, {tint:0xffff00})); //over.append(TweenMax.to(event.currentTarget.btn_txt, 1, {dropShadowFilter:{color:0xffffff, alpha:1, blurX:5, blurY:5, distance:2.5}})); } //------------------------------------------------ //BUTTON OUT FUNCTION function out(event:MouseEvent){//MAIN BUTTONS var out:TimelineMax = new TimelineMax(); out.append(TweenMax.to(event.currentTarget.btn_txt, .5, {removeTint:true})); } //*****====================================================***** var request:URLRequest = new URLRequest("homePage.swf");//HOMEPAGE var request1:URLRequest = new URLRequest("commercial.swf");//COMMERCIAL RELOCATION var request2:URLRequest = new URLRequest("residential.swf");//RESIDENTIAL RELOCATION var request3:URLRequest = new URLRequest("buyFurniture.swf");//BUY FURNITURE var request4:URLRequest = new URLRequest("sellFurniture.swf");//SELL FURNITURE var request5:URLRequest = new URLRequest("fileMoving.swf");//FILE MOVING var request6:URLRequest = new URLRequest("shredding.swf");//DOCUMENT SHREDDING var request7:URLRequest = new URLRequest("storage.swf");//STORAGE FACILITIES var request8:URLRequest = new URLRequest("cubicle.swf");//CUBICLE INSTALLATION var request9:URLRequest = new URLRequest("about.swf");//ABOUT US var request10:URLRequest = new URLRequest("faq.swf");//FREQUENTLY ASKED QUESTIONS var request11:URLRequest = new URLRequest("movePlanning.swf");//MOVE PLANNING var request12:URLRequest = new URLRequest("moveInstructions.swf");//MOVE INSTRUCTIONS var request13:URLRequest = new URLRequest("contact.swf");//CONTACT US //*****====================================================***** var contentLoader:Loader = new Loader(); var destX:Number = 0; var destY:Number = 325; //*****====================================================***** function scene(){ contentLoader.load(request) addChild(contentLoader); var fadeIn:TimelineMax = new TimelineMax(); fadeIn.append(TweenMax.to(contentLoader, .1, {alpha:0})); fadeIn.append(TweenMax.to(contentLoader,.25, {x:destX,y:destY})); fadeIn.append(TweenMax.to(contentLoader, 1, {alpha:1})); } scene(); //*****====================================================***** function clicked(event:MouseEvent):void{ switch(event.currentTarget.name){ case"commercial": TweenMax.to(contentLoader, 1, {alpha:0, onComplete:onFinish}); function onFinish():void { contentLoader.load(request1) addChild(contentLoader); trace(contentLoader); TweenMax.to(contentLoader,1, {x:destX, y:destY,alpha:1}); tracker.trackPageview("commercial"); } break; //------------------------------------------ case"residential": TweenMax.to(contentLoader,1, {alpha:0, onComplete:onFinish2}); function onFinish2():void{ contentLoader.load(request2) addChild(contentLoader); TweenMax.to(contentLoader,1, {x:destX, y:destY, alpha:1}); tracker.trackPageview("residential"); } break; //------------------------------------------ case"buyFurniture": contentLoader.load(request3) addChild(contentLoader); TweenMax.to(contentLoader,1, {x:destX, y:destY, alpha:1}); tracker.trackPageview("buyFurniture"); break; //------------------------------------------ case"sellFurniture": contentLoader.load(request4) addChild(contentLoader); TweenMax.to(contentLoader,1, {x:destX, y:destY, alpha:1}); tracker.trackPageview("sellFurniture"); break; //------------------------------------------ case"fileMoving": contentLoader.load(request5) addChild(contentLoader); TweenMax.to(contentLoader,1, {x:destX, y:destY, alpha:1}); tracker.trackPageview("fileMoving"); break; //------------------------------------------ case"shredding": contentLoader.load(request6) addChild(contentLoader); TweenMax.to(contentLoader,1, {x:destX, y:destY, alpha:1}); tracker.trackPageview("shredding"); break; //------------------------------------------ case"storage": contentLoader.load(request7) addChild(contentLoader); TweenMax.to(contentLoader,1, {x:destX, y:destY, alpha:1}); tracker.trackPageview("storage"); break; //------------------------------------------ case"cubicle": contentLoader.load(request8) addChild(contentLoader); TweenMax.to(contentLoader,1, {x:destX, y:destY, alpha:1}); tracker.trackPageview("cubicle"); break; //------------------------------------------ case"about": contentLoader.load(request9) addChild(contentLoader); TweenMax.to(contentLoader,1, {x:destX, y:destY, alpha:1}); tracker.trackPageview("menu.about"); break; //------------------------------------------ case"faq": contentLoader.load(request10) addChild(contentLoader); TweenMax.to(contentLoader,1, {x:destX, y:destY, alpha:1}); tracker.trackPageview("menu.faq"); break; //------------------------------------------ case"movePlanning": contentLoader.load(request11) addChild(contentLoader); TweenMax.to(contentLoader,1, {x:destX, y:destY, alpha:1}); tracker.trackPageview("menu.movePlanning"); break; //------------------------------------------ case"moveInstructions": contentLoader.load(request12) addChild(contentLoader); TweenMax.to(contentLoader,1, {x:destX, y:destY, alpha:1}); tracker.trackPageview("menu.moveInstructions"); break; //------------------------------------------ case"contact": contentLoader.load(request13) addChild(contentLoader); TweenMax.to(contentLoader,1, {x:destX, y:destY, alpha:1}); tracker.trackPageview("menu.contact"); break; } } //*****====================================================***** Link to comment Share on other sites More sharing options...
GreenSock Posted November 16, 2009 Share Posted November 16, 2009 It is still very tough to troubleshoot quickly without being able to publish an FLA, add trace() calls, etc. but I'll mention a few things: 1) Be very careful about using MOUSE_OVER/MOUSE_OUT instead of ROLL_OVER/ROLL_OUT. There can be a big difference that can cause headaches. Most developers need ROLL_OVER/ROLL_OUT. 2) Avoid nested functions whenever possible. I noticed you're using at least one. They are deleted from memory as soon as the parent function finishes running. You referenced one in an onComplete which won't work because by the time the tween is done, it will try to call a function that no longer exists. 3) There's no reason to use a TimelineLite/Max if you're only going to put one tween in it (like in your out() handler). Just fire off the tween, don't create a TimelineMax instance and then append() one tween. Hope that helps somehow. Link to comment Share on other sites More sharing options...
chefkeifer Posted November 16, 2009 Author Share Posted November 16, 2009 do you know of an example of or some sort of tutorial on the proper way to tween multiple external swf's i can't seem to find any.. Link to comment Share on other sites More sharing options...
chefkeifer Posted November 16, 2009 Author Share Posted November 16, 2009 by the way. I just donated another $100.00 to move myself up to the Shockingly Green member Link to comment Share on other sites More sharing options...
chefkeifer Posted November 16, 2009 Author Share Posted November 16, 2009 ok i changed my code up a bit..everything seems to be working fine but it doesnt seem the removeChild tweens..all the addChild tween in.. //*****====================================================***** var contentLoader:Loader = new Loader(); var swf:MovieClip; var destX:Number = 0; var destY:Number = 325; //*****====================================================***** var defaultSWF:URLRequest = new URLRequest("homePage.swf"); //*****====================================================***** contentLoader.load(defaultSWF); addChild(contentLoader); var fadeIn:TimelineMax = new TimelineMax(); fadeIn.append(TweenMax.to(contentLoader, .1, {alpha:0})); fadeIn.append(TweenMax.to(contentLoader, .1, {x:destX, y:destY})); fadeIn.append(TweenMax.to(contentLoader, 2, {alpha:1})); //*****====================================================***** function clicked(event:MouseEvent):void { TweenMax.to(contentLoader, 1, {alpha:0}); removeChild(contentLoader); var newSWFRequest:URLRequest = new URLRequest(event.target.name + ".swf"); contentLoader.load(newSWFRequest); addChild(contentLoader); var fadeIn2:TimelineMax = new TimelineMax(); fadeIn2.append(TweenMax.to(contentLoader, .1, {alpha:0})); fadeIn2.append(TweenMax.to(contentLoader, .1, {x:destX, y:destY})); fadeIn2.append(TweenMax.to(contentLoader, 3, {alpha:1})); } //*****====================================================***** Link to comment Share on other sites More sharing options...
GreenSock Posted November 16, 2009 Share Posted November 16, 2009 It almost looks like you're expecting each line of code to finish all its related tasks before moving on to the next line, but that's not how Flash works. For example: TweenMax.to(contentLoader, 1, {alpha:0}); removeChild(contentLoader); The first line creates a tween instance which will get updated on every ENTER_FRAME event until it finishes. But setting up the tween doesn't actually force Flash to stop all other tasks, wait the full second until that tween completes, and then move on to the next line of code. It just creates the tween instance and moves on. The second line immediately removes contentLoader. So when the tween actually starts fading contentLoader off, you'll never see it because contentLoader has been removed from the stage! Does that clear things up? Link to comment Share on other sites More sharing options...
GreenSock Posted November 16, 2009 Share Posted November 16, 2009 By the way, thanks for the donation! I sure appreciate the support of thoughtful developers like you. Link to comment Share on other sites More sharing options...
chefkeifer Posted November 16, 2009 Author Share Posted November 16, 2009 so how do I removed the contentLoader with a tween. Link to comment Share on other sites More sharing options...
GreenSock Posted November 16, 2009 Share Posted November 16, 2009 Use an onComplete. TweenMax.to(contentLoader, 1, {alpha:0, onComplete:onFinishFade}); function onFinishFade():void { removeChild(contentLoader); //other code here that should happen after the fade... } Link to comment Share on other sites More sharing options...
chefkeifer Posted November 16, 2009 Author Share Posted November 16, 2009 Thanks...now i can apply to that to my other projects. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now