Skip to main content
Known Participant
January 8, 2014
Question

Access movieclip on stage from class?

  • January 8, 2014
  • 2 replies
  • 996 views

Hi all,

Is it possible to access a movieclip which has been dragged onto the main stage in my FLA from an external class that i've written? Can i create a variable that refers to the object on the stage? Or does it have to be added dynamically to be accessible?

Many Thanks

Matt

This topic has been closed for replies.

2 replies

Amy Blankenship
Legend
January 9, 2014

All objects that are on the stage in Frame 1 are available in the constructor to the Class. If you want to use code completion to refer to the object turn off "declare stage instances automatically" and declare the instances in the file. You can declare them as a getter/setter pair, which will allow you to know when the instance has been populated by Flash even if it is not on Frame 1.

However, given your particular situation, you only need to break out your data and service Classes into Classes that do not extend MovieClip or Sprite. I'd suggest extending EventDispatcher, so that you can dispatch events when changes occur, such as when the load completes. When the main document Class or some other suitable Class hears that event, it can populate the variables accordingly.

I'd suggest that you not hard code the path to the XML in importXML. Note that static functions like you're using are really bad practice, especially in combination with the hard-coded path.

Ned Murphy
Legend
January 8, 2014

If you pass a stage reference to the class you should be able to target aything that is on it.

SFMltdAuthor
Known Participant
January 8, 2014

Hi Ned, thanks for the reply. Could you show me an example of how i'd go about that?

Many thanks

Matt

Ned Murphy
Legend
January 8, 2014

How do you implement the other class in the main file... how do you instantiate it?