Jump to content
Search Community

How to access to loaded content to call functions and properties?

own.on test
Moderator Tag

Recommended Posts

Hello

 

I'm just starting with TweenLite and TweenMax.

 

Please accept my apologies for this - I guess - very basic question :

 

I can load external swf on stage using TweenLite or TweenMax but the huge problem (for me :-/) is to get access to loaded content : function, properties, etc.

 

For example, I would like to send orders to a loaded swf to call internal swf functions or properties. In other way I'm seraching for the code who allow a virtual transparency of loaded content in order to interact with loaded content like normal content, on stage.

 

For example I load inside a container swf containing an instance of SlideShowPro inside a container but I cannot find the way to send things like :

 

container.(SlideShowPro-Instance-name).properties = something

 

or

 

call a function inside loaded swf.

 

How to virtualy get access to loaded content as it was on stage ?

 

Thank you very much in advance for your help !

Link to comment
Share on other sites

I assume you meant LoaderMax, right? The SWFLoader has a "rawContent" property that you can use to reference the swf's root (unless there are security restrictions, like if you're trying to subload from a different domain and you don't have a crossdomain.xml file in place - in that case the rawContent will be a Loader instance).

 

yourSWFLoader.rawContent.yourMethod();

 

However, I'm not familiar with SlideShowPro, so that may wrap things in another wrapper on the root, so you might need to reference things a bit differently (check with the makers of SlideShowPro for that). Maybe yourSWFLoader.rawContent.(SlideShowPro-Instance-name).properties.

Link to comment
Share on other sites

Thank you very much, it works fine!

 

I tried the opposite way : call a function in main stage from a loaded swf but ... without success.

 

I tried (loaded swf) :

 

MovieClip(parent).callFunctionMainStage();

 

and get:

 

TypeError: Error #1034: Type Coercion failed: cannot convert com.greensock.loading.display::ContentDisplay@22c9b061 to flash.display.MovieClip.

 

When I try

MovieClip(this.parent.parent).callFunctionMainStage();

 

I get :

 

TypeError: Error #1010: A term is undefined and has no properties.

at MethodInfo-1793()

Link to comment
Share on other sites

No no, not a subdomain, a crossdomain (like if the parent is on greensock.com and the child is at yahoo.com). Or did you use a distinct SecurityDomain in a LoaderContext? I wonder if the tool you're using does that (SlideShowPro). I'd encourage you to ask them about it (I'm not familiar with that tool).

Link to comment
Share on other sites

No no, not a subdomain, a crossdomain (like if the parent is on greensock.com and the child is at yahoo.com). Or did you use a distinct SecurityDomain in a LoaderContext? I wonder if the tool you're using does that (SlideShowPro). I'd encourage you to ask them about it (I'm not familiar with that tool).

 

No crossdomain.

To be sure SlideShowPro is not the cause I perform tests with 2 simple files:

 

test.fla:

 

 import com.greensock.*;
   import com.greensock.loading.*;
   import com.greensock.events.LoaderEvent;
   import com.greensock.loading.display.*;
   import com.greensock.TweenMax;


////////////////////////////////
// TwinMax Loaders //
////////////////////////////////

var mainContent:SWFLoader = new SWFLoader("sspViewerWork.swf", {name:"childMain", estimatedBytes:3000, container:container_main, x:0, y:0, alpha:1, onInit:initHandlerMain, onProgress:progressHandlerMain, onComplete:completeHandlerMain, onError:errorHandlerMain});
mainContent.load();

function initHandlerMain(event:LoaderEvent):void {
   //trace("initHandlerMain");
}

function progressHandlerMain(event:LoaderEvent):void {
   //trace(this);
   var childMain:ContentDisplay = LoaderMax.getContent("childMain");
   TweenLite.to(childMain, 1, {alpha:1});
}
function completeHandlerMain(event:LoaderEvent):void {
mainContent.rawContent.callFunctionInLoaded();
trace(mainContent.rawContent.test);
}
function errorHandlerMain(event:LoaderEvent):void {
   trace("error occured with " + event.target + ": " + event.text);
}
// END  TwinMax / TwinLite Loaders


////// try to get variables in swf
function callFunctionInMainFromLoaded() {
trace("this function located in main swf is called from the loaded swf")
}

 

and sspViewerWork.fla (loaded swf):

 

var test:String;
test = "variable loacated in loaded swf";
//trace("trace in swf");

function callFunctionInLoaded() {
trace("this function is in the loaded swf");
}

MovieClip(this.parent.parent).callFunctionInMainFromLoaded();

//var curParent:DisplayObjectContainer = this.parent.parent;
//   Object(curParent).callFunctionInMainFromLoaded(); // NO

//var parentObj:Object = this.parent.parent as Object;
//parentObj.callFunctionInMainFromLoaded(); // NO

// MovieClip(parent).callFunctionInMainFromLoaded(); // NO

//callFunctionInLoaded();

Link to comment
Share on other sites

From looking at your code, I think you are not going up the display list enough levels.

Below is what I assess to be the nesting of your assets

 

root of parent clip > container_main > contentDisplay sprite of SWFLoader > actual rawContent (root of loaded swf)

 

If you do this.parent.parent you are only getting to container_main.

 

try:

 

MovieClip(this.parent.parent.parent).callFunctionInMainFromLoaded();

Link to comment
Share on other sites

Sorry, there needs to be 1 more parent.

the parent of any timeline is [object Stage]

 

I made an example that works:

parent.fla

 

import com.greensock.loading.*;

var holder_mc:MovieClip = new MovieClip();

addChild(holder_mc)

var swf:SWFLoader = new SWFLoader('child.swf', {container:holder_mc});
swf.load();


function doStuff(){
trace("child told me it was loaded");
}

 

child.fla

 

trace(this.parent.parent);
// if child swf is loaded into parent this will be [object ContentDisplay]
//if child is running on its own it will be null


// if parent.parent exsits, then call doStuff() function in parent.swf
if(this.parent.parent){
MovieClip(this.parent.parent.parent.parent).doStuff();
}

 

 

cs5 files attached. hope this helps

callFunctionInParentSwfFromChild_CS5.zip

Link to comment
Share on other sites

  • 1 year later...

Hi and welcome to the GreenSock forums,

 

Yes, as far as I can recall, I was serious. 

Please keep in mind the topic of this post relates specifically to calling functions from one object to another.

In order to call a function on another object, you must know where it is in the display list ( or have a valid reference to it). Not sure there is a way around that.

 

However, another approach would be to dispatch a custom Event from your loaded swf and have the parent swf listen for that event.

A great resource for learning about AS3 events can be found here: http://code.tutsplus.com/tutorials/as3-101-events-basix--active-10018.

Link to comment
Share on other sites

  • 1 year later...

I assume you meant LoaderMax, right? The SWFLoader has a "rawContent" property that you can use to reference the swf's root (unless there are security restrictions, like if you're trying to subload from a different domain and you don't have a crossdomain.xml file in place - in that case the rawContent will be a Loader instance).

 

yourSWFLoader.rawContent.yourMethod();
However, I'm not familiar with SlideShowPro, so that may wrap things in another wrapper on the root, so you might need to reference things a bit differently (check with the makers of SlideShowPro for that). Maybe yourSWFLoader.rawContent.(SlideShowPro-Instance-name).properties.

 

Does rawContent still work in the most recent Greensock Loadermax?

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