Skip to main content
Known Participant
June 2, 2011
Question

Child > Parent >child preloading as3

  • June 2, 2011
  • 1 reply
  • 1595 views

I have been using:

yourbutton.addEventListener(MouseEvent.CLICK,f);

function f(e:Event):void{

Loader(this.parent).load(new URLRequest("newswf.swf"));

}

which was suggested to me in a different post to target the parent loader class, however i now no longer can reference my preloader in the parent swf

(extract from the parent swf):

var my_pb:ProgressBar = new ProgressBar();

my_pb.source = my_loader.contentLoaderInfo;

my_pb.x = 305;

my_pb.y = 293;

my_loader.load(new URLRequest("contentLoader.swf"));

this.mainTemplate.mcMaskedClip.addChild(my_pb);

my_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading);

function finishLoading(e:Event):void{

this.mainTemplate.mcMaskedClip.addChild(my_loader);

this.mainTemplate.mcMaskedClip.removeChild(my_pb);

}

How do i target  the parent loader class to use the preloader?

the reason i need a pre loader are the swf files i am loading are fairly big i.e. 2-5mb

keith

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
June 3, 2011

from your loaded swf's main timeline (before unloading, of course), you would use:

Movieclip(this.parent.parent).my_pb

conyipAuthor
Known Participant
June 3, 2011

i Seem to be getting errors in the parent swf when i add it to my button event in my loaded swf :

sgWeb1_btn.addEventListener(MouseEvent.CLICK, coreOne);

function coreOne(e:Event):void {

Loader(this.parent).load(new URLRequest("SGCORE1.swf"));

MovieClip(this.parent.parent).my_pb;

}

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at contentLoader_fla::MainTimeline/coreOne()

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.

at flash.display::DisplayObjectContainer/removeChild()

at SG_Main_opt2_fla::MainTimeline/finishLoading()

SG_main (timeline):

my_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading);

function finishLoading(e:Event):void{

this.mainTemplate.mcMaskedClip.addChild(my_loader);

this.mainTemplate.mcMaskedClip.removeChild(my_pb);

any ideas what is causing this error?

kind regards

Keith

kglad
Community Expert
Community Expert
June 3, 2011

before unloading:


sgWeb1_btn.addEventListener(MouseEvent.CLICK, coreOne);

function coreOne(e:Event):void {

MovieClip(this.parent.parent).my_pb;  // this isn't doing anything

Loader(this.parent).load(new URLRequest("SGCORE1.swf"));  // <-  and you're unloading "this" here

}