calling a function on Hosting Flex App from loaded AS3 SWF

Posted on 2007-10-15
Medium Priority
Last Modified: 2012-05-05
I have a flex application that uses SWFLoader to load an Actionscript3 SWF.
I want to have access from the loaded SWF to a global variable in the Flex application.
I expected to be able to do something like root.parent.root['variablename']  but it does not work.
Any ideas on how can I do this ?
alternativly can I call a global function on the hosting flex App and get an object as a result?

Question by:SnowFlake
  • 3
  • 2
  • 2
  • +1

Expert Comment

ID: 20079452

This might help if not then try posting a question on there, the response rate is pretty good and they focus on just Flex.
LVL 10

Accepted Solution

Savong earned 2000 total points
ID: 20079756
You might try referencing parentApplication, or Application.application.  Depending on context these may or may not work as you're expecting, but they should give you access to any public variables in the main Application MXML.
LVL 15

Author Comment

ID: 20091395
sorrt, i could not find it there.
if I won't find an answer here I might try posting there as well.

What you say is interesting but being a beginer in FLEX I am not exactly sure how to us it.
I understand that you say that from the loaded swf I should get a handle to the application object of the hosting (parent) application and then use it to get to the public variabels but what would be the syntax  ?specifically of the second part - would it be something like handleToParentApp['varName']  ??

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 10

Expert Comment

ID: 20094489
Application.application is somewhat similar to _root in AS2.  The call might look like:

Though depending on the exact implementation other methods might be needed.
LVL 15

Author Comment

ID: 20097861
took some trail and error but finally I got
root.parent is the Flex SWFLoader
root.parent.parent is an mx.core systemManager
which had the parentApplication attibute which in turn has attributes for the global variables

Thanks for pointing me to the parentApplication Property.

for those reading this not understanding why I use ['parentApplication'] and not .parentApplication
its becuase otherwise the flash compiler complains about it. using the first syntax prevents the complaint.

LVL 19

Expert Comment

by:Gary Benade
ID: 20230750
LVL 15

Author Comment

ID: 20318724
thanks for you additional input,
1) as I indicated above I already have what I needed working
2) I am also aware of local connections but it is more complex.  I can not just ask the "host" to add a function and be able to call it. It also has the disadvantage (for my current needs) of beeing async.
3) the second link is for the other wa around ( host to hosted communications).


Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question