Skip to main content
Participant
February 27, 2008
Answered

Best way to target a loader swf?

  • February 27, 2008
  • 5 replies
  • 614 views
In AS2 I created tons of projects where I used _level0 as my main menu and loaded other swfs (e.g. tutorial chapters) into and out of _level1. My swfs in _level1 would access variables such as dates, user name, and such residing in _level0. I am recreating all of this in AS3 using the loader class which works great until I try to access variables in my main swf. For example, menu.swf has a button that loads chapter_1.swf. This chapter_1.swf needs to access a string variable called userName in menu.swf and display it in a text field. In AS2 I would simply write user_txt.text = _level0.userName. How do I do that in AS3? I know it is probably very easy but I have not been able to target menu.swf. I have searched high and low for this answer but I must not be searching correctly.

Thank you in advance for any help you may be able to provide.
This topic has been closed for replies.
Correct answer TreeHugger98
Rob,

You were very close to the solution in your first response. I added an additional parent to your code and it worked. I think that's what kglad was trying to tell me. The single parent was pointing to the loader itself versus the main timeline. So the correct code is:

MovieClip(parent.parent).userName

Thanks to both of you for your help.

5 replies

kglad
Community Expert
Community Expert
February 29, 2008
you're welcome.
robdillon
Participating Frequently
February 28, 2008
Show us the code that you are using that is causing this error.
TreeHugger98AuthorCorrect answer
Participant
February 29, 2008
Rob,

You were very close to the solution in your first response. I added an additional parent to your code and it worked. I think that's what kglad was trying to tell me. The single parent was pointing to the loader itself versus the main timeline. So the correct code is:

MovieClip(parent.parent).userName

Thanks to both of you for your help.
Participant
February 28, 2008
parent.parent also gives an error: 1119: Access of possibly undefined property userName through a reference with static type flash.display:DisplayObjectContainer.
kglad
Community Expert
Community Expert
February 28, 2008
use parent.parent.
robdillon
Participating Frequently
February 28, 2008
Try MovieClip(parent).userName
Participant
February 28, 2008
That throws the following error: TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Loader@34cb061 to flash.display.MovieClip.

Is there a way I can cast the parent as a movie clip?