Search Unity

Communicate From Unity .swf to Flash

Discussion in 'Flash' started by bradswardson, Dec 12, 2012.

  1. bradswardson

    bradswardson

    Joined:
    Dec 12, 2012
    Posts:
    1
    Hey all,

    I am working on testing Unity as an engine to use as a piece of a Flex Application I am writing. What I am attempting is for a user to select a model inside Unity and have information about that model communicated back to Flash. This could just be an ID, a name or something unique to identify the model.

    I have looked at the embeddingapi and the IUnityContent methods and can see how I can send messages from Flash to Unity, but not the other way. I also see that I can read information about the unity project, loading progress etc. but not specific information from Unity once the project is loaded.

    My hope was that i could fire a custom AS3 event from the Unity swf. Apply an event listener to the UnityLoader for that event and then pass the unique model payload with the event and do it that way, but I am not sure if Unity can fire custom AS3 events.

    Is there any way to communicate this kind of information back to Flash based on mouse events like click, roll over, roll out etc.

    Thanks!
     
  2. mtoivo

    mtoivo

    Joined:
    Jul 30, 2012
    Posts:
    274
    Hi, and welcome to the forums.

    I've tossed data between Flash and Unity bi-directionally without a problem. You're talking about embeddingapi[.swc], so I take it you're on 4.0. Not much differences between 3.5, but I got I a simple example to demostrate how you can manage it, and the project is in 4.0 format. Take a look here for links and stuff: [Flash] Example Flash UI over Unity SWF Content. It's done in C#, but the same behaviour is of course available via US, too.

    Everything you suggested should be easily implemented in Unity, you can consider the unity.swf just another MovieClip inside your FB project. After making it aware of it's place in the hierarcy (by supplying information about it's parent such), you can easily do whatever you like with it. When all you want to do is a few lines of AS3 on the Unity side, you can probably get away with ActionScript.Statement() quite easily. For more complicated things, you might want to wrap your implementation inside a custom static AS3-class, from which you can call methods via in C#/US like they were native C#/US methods.