A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Share class question

  1. #1
    Senior Member
    Join Date
    Dec 2006
    Location
    Jax, FL
    Posts
    110

    Share class question

    Hello everyone.
    Let me try to setup the senerio. If you load a class on the main movie and then drop a swf on the stage. Does the swf that you drop on the stage have access to the main move class? I use to be able to do this in AS1.

    So it is safe to say that:
    In AS3, all swf's are self contained and parameters can only be passed to the imported swf.

    If I want to be able to use a (global) class, I need to develop all submovies (swf's) as packages.

    Any suggestion would be great.

  2. #2
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    I'm not clear what you are trying to pass to the loaded movies but here is the rundown on communication with loaded movies:

    if your main movie AND loaded movie are AS3 based...use a loader to load it and pass it parameters using the loader class (much faster than the old localConnection and you can pass all kinds of data in huge amounts).

    if your main movie is as3 based AND your loaded movie is as1 based, use a localConnection instead.

    if both movies are as1 based, use a localConnection

  3. #3
    Senior Member
    Join Date
    Dec 2006
    Location
    Jax, FL
    Posts
    110
    Simple senario.
    Create a movie with pushbutton. Add an event to the button to call a function root.bpress()
    Save this movie and create a swf.

    Now open a new move and use the import object to drop the previous created move onto the stage. Add a function bpress() to the script.

    When you play the movie and press the pushbutton will the event be passed to the new movie?

  4. #4
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    i can't speak for dropping in an swf (using import swf). I don't do things that way so maybe Bob can help and tell you if methods in an imported swf are available to the parent. I say this because when I import an swf this way...I run the risk of actionscript getting skewed...the more complicated the scripting in an imported swf...the more the chance IMO. Maybe this is no longer the case but I prefer to use loader(for many reasons) and can only speak to what I know. Seeing as I can reuse a loader object, i'd rather send external movies to it and use it's wonderful abilities to communicate with loaded swf assets (which are also as3 based).

    If you are in fact using a loader to load this external movie (and both are as3)...yes...you certainly can pass anything you want to it using the loader class. You can also destroy it (if need be) and your compiled main movie size is smaller as the external asset is loaded at runtime.

  5. #5
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    You shouldn't drop a movie on stage in this case.
    If you use the Loader class to load an external movie, you can control the interaction behaviour using the applicationDomain property of a LoaderContext object.
    http://livedocs.adobe.com/flash/9.0/...licationDomain

    The intended behaviour of the import function KM has is to separate the loaded content from the parent as much as possible to prevent problems when both the parent and the movie that will be loaded use same class names for different things.
    Last edited by w.brants; 04-15-2009 at 12:20 PM.

  6. #6
    Senior Member
    Join Date
    Dec 2006
    Location
    Jax, FL
    Posts
    110
    Why?
    Well, if the ablility exists then classes that have global functions can be added to the main movie and used in all submovies. Example would be a socket class. A single connection could exists for all communications with the server. Instead of dropping the connection each time a new submovie needs access to the server.

    Any ideas on the best approach to the example are welcome.
    Last edited by imdumb; 04-15-2009 at 12:25 PM.

  7. #7
    Senior Member
    Join Date
    Dec 2006
    Location
    Jax, FL
    Posts
    110
    Thanks everyone, will drill into the loadercontext object.

  8. #8
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Explain what is being passed and we will attempt to explain you are overcomplicating things relying on deprecated methods.

    As a rough example of usage...lets say I had a list of video urls in my main (whether hard coded or as a result of a server side call...doesn't matter as long as they exist). I then load an external movie that contains a mediaplayer (for example). I can send individual url's (or packs of them) to this loaded mediaplayer using the loader class more efficiently than the old days and can reuse the same loaded asset. I can send it an entire playlist as xml if i wish. I can control any part of the loaded asset as long as there are functions coded in it to accept the sent command from the main. That is one way communication...for two way Wilbert has posted a great link.

    Granted I have no idea of what you are doing in reality but am trying to make you see there is method to what you see as madness

  9. #9
    Senior Member
    Join Date
    Dec 2006
    Location
    Jax, FL
    Posts
    110
    Thanks, W.
    Chris the question was not meant to be complex, it revolved around loading swf's and how they communicate with the main movie. The flash_as3_programming guide explains it very well. Anyone that will be loading swf's from different domains should read over this material.
    The applicationDomain is very important to how and where your swf's are loaded.

    Line of code that is important when using the loader object.
    ex: loader.load(request,new LoaderContext(false, new ApplicationDomain()));

    I would explain more but the guide says it all.
    Thanks again W. and Chris

  10. #10
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    Moock covers it heavily in Essential AS3 also with many real world scenarios. Sounds like you have a better understanding and lots of fun ahead!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center