Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Steven P123

SWFLoad delivers Error #1009 - Sometimes

Recommended Posts

Greetings and best wishes for the-day-after-thanksgiving.
 
I've been trying to get my head around loading SWFs. I have a number of SWFs that I wanted to play one after the other and can not accomplish this (always starts the last one loaded), so I wanted to just load a SWF in an existing FLA.
 
The FLA is a three frame deal where I run through a bunch of tweens and timelines in each frame and when the final tween completed, we go to the next frame. So I figured all I had to do was create a frame with this:
 

stop();

import com.greensock.*;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.*;
import com.greensock.loading.display.*;
import flash.events.Event;
import com.greensock.*;
import com.greensock.plugins.*;
import com.greensock.easing.*;
 
function Part01() {
    var holder = new MovieClip();
    addChild(holder);
    var loader:SWFLoader = new SWFLoader("typing.swf", {container:holder});
    loader.load();
}

Part01();

The SWF starts but reaches a certain place (same every time) and unfortunately, this returns a seeming infinitely looping error:

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

So, I removed the first three frames so that this frame and layer - and only this frame and layer - existed. I tested the movie again and it worked like a champ with no errors: the SWF was loaded and played.

 

 

So .... why am I getting errors loading this into the final frame of an existing project?

 

Thanks,

Steven P.

Link to comment
Share on other sites

I should also have written that all assets particular for one frame do not exist on any other frame.

 

Thanks for reading and a great weekend to all.

Link to comment
Share on other sites

I don't really know why this isn't working. If you can provide a very simple example that only contains enough code and assets to replicate the error we can take a look. My guess is that maybe the parent isn't really stopping on that frame with all the code (i did see the stop()) Sounds like perhaps its moving from that frame prematurely, as you stated that it works when there is only 1 frame. 

 

FWIW you can visit this page here http://www.snorkl.tv/2011/11/snorklreport-big-news/and scroll down to 

Something Free and Fun for YOU!

There are source files for a demo that loads in 4 swfs and plays them all in succession. Maybe that will help you see a different way of doing this.

Link to comment
Share on other sites

Thanks Carl. I'd actually already found your CS4 fla and tried it. This is the output (after I change the names of the 4 SWFs to the ones I want to play):

SWFLoader 'loader2' (dev_stone_and_ivy-03.swf) loaded
SWFLoader 'loader1' (typing.swf) loaded
SWFLoader 'loader3' (clusterBomb-windgetland-dev-1_0.swf) loaded
SWFLoader 'loader4' (AS3-widgetland_dev-1_4.swf) loaded
all swfs loaded
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at loadSWFsPlaySequence_fla::MainTimeline/initCurrentLoader()
	at loadSWFsPlaySequence_fla::MainTimeline/completeHandler()
	at flash.events::EventDispatcher/dispatchEventFunction()
	at flash.events::EventDispatcher/dispatchEvent()
	at com.greensock.loading.core::LoaderCore/_completeHandler()
	at com.greensock.loading::LoaderMax/_loadNext()
	at flash.events::EventDispatcher/dispatchEventFunction()
	at flash.events::EventDispatcher/dispatchEvent()
	at com.greensock.loading.core::LoaderCore/_completeHandler()
	at com.greensock.loading::SWFLoader/_completeHandler()

Again, a 1009 error. The four SWFs I created were single-frame movies using Greensock code, and work fine stand-alone.

 

I'll try to distill the code, but each are rather complex; to me, anyway.

 

Thanks,

Steven P

Link to comment
Share on other sites

 

There is no way for the parent swf to know what functions to call or what TimelineLite/Max instances to play()… although you very well could program this in.

 

Does this mean that I cannot use Greensock-powered SWFs with your solution Carl? I ask because using CS4 to open the four sub-FLAs resulted in "unknown file type" errors, so I could not see for myself.

Link to comment
Share on other sites

No, you can use GreenSock animations in the child swfs.

The demo I provided used the parent to check if the child's animation had reached its final frame.

 

Using a GreenSock animation, let's assume a TimelineLite, you would take another route.

Each child would have a timeline animation with the same name, let's call it animation.

The parent would tell the swf of the current SWFLoader to play its animation like

 

currentSWFLoader.rawContent.animation.play().

 

The parent swf could then repeatedly check to see if animation.progress() == 1 (completed)

or the child swf's animation could have a callback that told the parent to play the next animation in the next swf.

 

I might be able to get you a demo of this after the weekend, however I don't think I can export out to CS4.

  • Like 1
Link to comment
Share on other sites

Thanks Carl. Let me play with that concept today. I'll have to re-think the child SWFs (not at all a bad thing) since they are each multiple timelines and functions rather than a single timeline.

 

Thanks for helping me learn to fish, Carl.

Link to comment
Share on other sites

Carl, I'm sorry but I can't figure out how to do "animation.progress() == 1", nor doing a callback from the child SWFs. I guess I don't code often enough to have a grasp on what are probably basic concepts.

Link to comment
Share on other sites

Here is a demo of a Main fla that loads 2 child swfs. Each child swf contains a TimelineMax animation.

When each child swf gets loaded the parent (main) uses addEventListener to assign a COMPLETE listener to the TimelineMax in the child.

So when each child finishes playing it basically calls a function in the Main fla to show the animation in the next swf.

 

Here is the pertinent code in the parent:

 

public function childCompleteHandler(e:LoaderEvent):void {
trace(e.target + " loaded");
e.target.content.visible = false;
//pause the TimelineMax in the loaded swf:
e.target.rawContent.tl.pause(0);
//when each swf is loaded assign it a COMPLETE listener which will trigger the next swf's TimelineMax to play.
e.target.rawContent.tl.addEventListener(TweenEvent.COMPLETE, childTimelineComplete)
}


public function completeHandler(e:LoaderEvent):void {
trace("all swfs loaded");
progress_mc.visible = false;
initCurrentLoader();
}


public function initCurrentLoader() {
loaderIndex++;
if (loaderIndex == swfs.numChildren) {
//reset back to 0 if the last swf has already played
loaderIndex = 0;
}
//dynamically reference current loader based on value of loaderIndex
currentLoader = swfs.getChildAt(loaderIndex);
//make the content of the current loader visible
currentLoader.content.visible = true;
//tell the current loader's swf's TimelineMax to to play
trace("restart " + currentLoader);
currentLoader.rawContent.tl.play(0);


}




public function childTimelineComplete(e:Event):void {
trace("swf done");
//hide and stop current swf
currentLoader.content.visible = false;
//set up and play the next swf;
initCurrentLoader();
}

Each child swf has a document class like this with a simple TimelineMax

 

package  {


import flash.display.MovieClip;
import com.greensock.*;
import flash.events.Event;
public class Child1 extends MovieClip {


public var tl:TimelineMax;


public function Child1() {
if (stage) {
init();
} else {
addEventListener(Event.ADDED_TO_STAGE,init);
}


}


private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE,init);
tl = new TimelineMax();
tl.to(mc, 1, {x:300})
 .to(mc, 1, {y:200});


}
}


}

Attached are CS5 fla files and the document classes for Main.as, Child1.as, Child2.as

 

 

controlTimelinesInLoadedSwfs.zip

  • Like 1
Link to comment
Share on other sites

Carl, thank you very much!!

 

I think that'll keep me busy for a couple of days. :lol:

 

Best,

Steven P.

Link to comment
Share on other sites

Carl, thanks for taking the time to build that package for me.

 

I downloaded the trial of CS6 and after successfully executing main.fla, I copied it to a different file (changing the document class as well) and commented the main.as so that just Child1 ran. this worked fine. Then I adjusted main.as so that it would play one of my animations which I had prepared by removing it's action script and placing it in widgetland.as (which was a copy of Child2.as with corrected class & function declarations).

 

Unfortunately, I have an error returned over a property for a movie clip within my animation which is not scripted in any way:

SWFLoader 'loader1' (Child1.swf) loaded
ReferenceError: Error #1056: Cannot create property mc_name_rust on widgetland.
	at flash.display::Sprite/constructChildren()
	at flash.display::Sprite()
	at flash.display::MovieClip()
	at widgetland()

I tried removing the instance of that clip, but another clip was then the stopping point (cannot create property mc_background on widgetland).

 

My widgetland.as:

package  {
	
	import flash.display.MovieClip;
	import com.greensock.*;
	import com.greensock.easing.*;
	import flash.events.Event;
	public class widgetland extends MovieClip {
		
		public var tl:TimelineMax;
		
		public function widgetland() {
			if (stage) {
				init();
			} else {
				addEventListener(Event.ADDED_TO_STAGE,init);
			}

		}

		private function init(e:Event = null):void {
			removeEventListener(Event.ADDED_TO_STAGE,init);
			tl = new TimelineMax();
			//tl.to(mc, 1, {x:300})
			//  .to(mc, 1, {y:200});
			tl.insert( TweenLite.to(mc_logo_globe, 6, {rotation:"765", delay:3}) );
			
				tl.insert( TweenLite.from(mc_gear_left, 6, {alpha:0, ease:Linear.easeNone}) );
				tl.insert( TweenLite.from(mc_gear_center, 6, {alpha:0, ease:Linear.easeNone}) );
				tl.insert( TweenLite.from(mc_gear_right, 6, {alpha:0, ease:Linear.easeNone}) );
			
				tl.insert( TweenLite.to(mc_gear_left, 4, {rotation:"-336", ease:Linear.easeNone}) );
				tl.insert( TweenLite.to(mc_gear_center, 4, {rotation:"336", ease:Linear.easeNone}) );
				tl.insert( TweenLite.to(mc_gear_right, 4, {rotation:"-336", ease:Linear.easeNone}) );
			
				tl.insert( TweenLite.from(mc_logo_globe, 4, {alpha:0, scaleX:0, scaleY:0, rotation:"-1440"}) );
		}

	}
	
}

Thanks Carl,

Steven P

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