Skip to main content
saratogacoach
Inspiring
July 15, 2014
Answered

AS3 pass variables-values from loaded external swf to parent swf

  • July 15, 2014
  • 2 replies
  • 4723 views

Hi,

I am working on an eLearning project that uses a main SWF (SWF1) and a second SWF (SWF2) with 2 quizzes in it. Published to AIR for Desktop and Android, SWF1 and SWF2 are packaged together in the AIR desktop or AIR APK exports.

I can use a loader in SWF1 to call and run SWF2. What I am having difficulty with, need some help, is how to get the 2 scores from the 2 quizzes in SWF2 and load these values (each is a Number) back into SWF1. Once back in SWF1, they will be written to String and then displayed in a text box using textbox.text.

While I've searched online and found examples for sending variables from parent to child SWF's, so far not able to find an understandable/useable AS3 script example for getting variables from child to parent SWF.

Any help appreciated.

Best Wishes,

This topic has been closed for replies.
Correct answer kiran1989

The better way to communicate between parent and child swfs is through events. Dispatch an event from child with data to be send and catch the event at parent level. This flow is common and very easy to handle

2 replies

kiran1989
Inspiring
July 15, 2014

Hi Saratogacoach,

I made a small example for you hope you understandard the code.

You can download the example frome here:

http://d.pr/f/4yK7R

Thanks

Kiran

saratogacoach
Inspiring
July 15, 2014

Thank you, Kiran.

I understand the code but will need to study to figure out how to use it. I think that the "child.swf" has the code for what I would call my SWF2: the second SWF (SWF2) with the 2 quizzes from which I want to send the 2 quiz scores-score1 and score2 back to the main SWF (which I am calling SWF1) that has launched the second SWF. Then the main SWF (SWF1) can convert the scores (numbers) to String and display them for the quiz taker in 2 text boxes in SWF1.

I will try to get it to work and update if I am successful.

Thank you very much.

saratogacoach
Inspiring
July 16, 2014

Hi Kiran,

Thank you for your help. As I mentioned above in another posting, the project is large, and I can not provide it.

The main/parent SWF, SWF1, has a couple of hundred frames with multiple quizzes, learning materials. But, before the first quiz is taken in SWF1, 2 other quizzes need to be completed by the user in SWF2, the child swf. So, in SWF1, frame 2 a button is used to load and run SWF1. When SWF1 loads and opens, the user takes the 2 quizzes and get 2 scores (these 2 score variables, with your help with the script, can now be sent to SWF1, using the dispatch event in SWF2 and the AppEvent listener in SWF1). After completing these 2 quizzes in SWF2, sending back the 2 score variables to SWF1, then I would like the user to return back to SWF1, frame 2 (the SWF1 loading frame where the button loaded SWF2). From there, they can go forward to the next frame and take the next SWF1 quiz.

I had originally put all of the quizzes, now in SWF1 and SWF2 in the same SWF, but because of very fast timing like 400 ms or 600 ms, there were too many functions, code and this ruined the timing. So I separated 2 big quizzes and put them, instead, into a new SWF: SWF2. But now I am stuck trying to load SWF2 from inside SWF1, get back the 2 quiz scores into SWF1, and return the user from SWF2 back to SWF1, so they can go to the other quizzes.

I hope this is a better explanation. Please ask for any additional clarification, information.

Again, thank you for your help.

Kind Regards,


Hi Kiran,

I just sent you a message with a download link for the 2 FLA's for this project (made smaller by removing unnecessary frames, materials-I included your AppEvent class AS file that you provided). Thank you for your help. Please let me know if you need any additional information or clarification.

Kind Regards,

kiran1989
kiran1989Correct answer
Inspiring
July 15, 2014

The better way to communicate between parent and child swfs is through events. Dispatch an event from child with data to be send and catch the event at parent level. This flow is common and very easy to handle

saratogacoach
Inspiring
July 15, 2014

Hi Kiran

Thank you for your reply and helpful suggestions. I am an amateur at scripting in AS3, so it would be a big help if I had an example, if possible.

Best Wishes,