Jump to content
Search Community

Noob question - sorry

acto test
Moderator Tag

Recommended Posts

Hi,

 

I'm using LoaderMax to load an swf into a main container, in my loaded swf I have a button, I would like to get this button to trigger a function in my container, I tried these methods:

 

1 - In my loaded swf I have my button call the function that is defined in my main movie:

 

linkButton.addEventListener(MouseEvent.CLICK, linkButtonClick);

function linkButtonClick(e:MouseEvent): void {
MovieClip(parent.parent).myFunction();
}

 

This returned an error...

 

2 - I tried to add an event listener to the LoaderMax onCompleteHandler:

 

function completeHandler(event:LoaderEvent):void {
    trace(event.target + " is complete!");

var loadedSWF:MovieClip;

   loadedSWF = MovieClip(event.currentTarget.content);
function linkButtonClick(e:MouseEvent): void {
myFunction()
}
}

 

This doesn't work at all, I probably have syntax errors...

 

I don't know how to do this, could you lease help, I'm stuck :(

 

Thank you in advance,

 

acto

Link to comment
Share on other sites

I got the following to work with no errors.

 

in the main movie that loads in your loaded swf have a function like:

 

function onParentFiredFromLoaded(){
trace("the sub clip called this function in the parent container movie");
}

 

in your loaded external swf have something like:

 

 

btn.addEventListener(MouseEvent.CLICK, test);

function test(e:Event){
trace("fired from btn");
trace(this.parent.parent as MovieClip);
var parentMovie:MovieClip = this.parent.parent as MovieClip;
parentMovie.onParentFiredFromLoaded();


}

Link to comment
Share on other sites

Hi,

 

Thank you for your help but I'm getting an error: TypeError: Error #1006: onParentFiredFromLoaded is not a function.

at s01_01_fla::MainTimeline/test()

 

In my loaded swf I have this code:

 

linkButton.addEventListener(MouseEvent.CLICK, test);

function test(e:Event){
  trace("fired from btn");
  trace(this.parent.parent as MovieClip);
  var parentMovie:MovieClip = this.parent.parent as MovieClip;
  parentMovie.onParentFiredFromLoaded();
}

 

and in my main swf I have this:

 

function loadSubSections(): void {
if (s01Instance == s01S01 && s01S01Loaded != 1) {
var loader:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});


loader.append( new SWFLoader("s01_01.swf", {name:"subSection01", estimatedBytes:3000, container:Object(root).s01s01_container, autoPlay:true}) );

loader.load();

function progressHandler(event:LoaderEvent):void {
trace("progress: " + event.target.progress);
}
 
function completeHandler(event:LoaderEvent):void {
trace(event.target + " is complete!");
}
}

function onParentFiredFromLoaded(): void {
  trace("the sub clip called this function in the parent container movie");
  }

 

Can you see what's wrong? I don't get it...

 

acto

Link to comment
Share on other sites

i think i see it, you are loading your clip into a different container than me.

 

you have:

loader.append( new SWFLoader("s01_01.swf", {name:"subSection01", estimatedBytes:3000, container:Object(root).s01s01_container, autoPlay:true}) );

 

and your function doesn't live in s01s01 it lives on the root stage

 

and i was loading directly into the main timeline aka this

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

 

try adding one more parent to your path

 

trace("fired from btn");

trace(this.parent.parent as MovieClip);

var parentMovie:MovieClip = this.parent.parent.parent as MovieClip;

parentMovie.onParentFiredFromLoaded();

Link to comment
Share on other sites

Ok I got it to work... wheeew :)

 

The problem was the ()

 

This does not work:

 

function test(e:Event){
  trace("fired from btn");
  trace(this.parent.parent as MovieClip);
  var parentMovie:MovieClip = this.parent.parent as MovieClip;
  parentMovie.onParentFiredFromLoaded();
}

 

This works:

 

function test(e:Event){
  trace("fired from btn");
  trace(this.parent.parent as MovieClip);
  var parentMovie:MovieClip = this.parent.parent as MovieClip;
  parentMovie.onParentFiredFromLoaded;
}

 

Thank you for your help, I really appreciate it!

 

acto

Link to comment
Share on other sites

Ok, sorry for the last post, it still doesn't work :(

 

I'm not getting the error but can't call the onParentFiredFromLoaded function...

 

I will try something and get back with the results, hopefully they will be positive,

 

Thx,

 

acto

Link to comment
Share on other sites

OK!!!

 

Now it works,

 

This is the code:

 

function test(e:MouseEvent){
  trace("fired from btn");
  trace(parent.parent.parent as MovieClip);
  var parentMovie:MovieClip = parent.parent.parent as MovieClip;
  parentMovie.onParentFiredFromLoaded();
 }

 

 

Thank you for your help and putting me on the right track :)

 

acto

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