A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Communicate with SWF embedded in ActionScript project

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    11

    Communicate with SWF embedded in ActionScript project

    I'm programming my game using Flash Builder 4, in an "ActionScript project". I'm not using Flex. I want to build my menus and cutscenes in Flash Professional, then export them as SWF and embed them into my final project.

    Embedding the SWFs works fine, I do something like this:
    Code:
    [Embed(source = 'test.swf')] private var SwfClass:Class;
    var myMovieClip:MovieClip = new SwfClass();
    parent.addChiled( myMovieClip )
    My problem is that I can't access the buttons and other elements of the SWF that I need to communicate with and manipulate. For example, the main menu will have a "Play" button. I need to know if that button has been pressed. The level select screen will have a "Best Time" text field, that should show the player's best time on a level - this text needs to be set. But I can't figure out how to access these things.

    I don't think that the children of the MovieClip are visible within my Actionscript project - it seems like the SWF is loaded in as one big "chunk" that can't be interacted with (it plays fine though).

    So what is the best way to interact/communicate with an embedded SWF? I've found a bit of information on the topic, but usually people are talking about using Flex or loading in external SWF (which seems to behave different from embedding). Is there even a way to do this?

    Thanks a lot!

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    Are you using the SDK? Why are you not loading the Flash movie using the Loader?
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    11
    I assumed that embedding it in the way that I did would be using Loader automatically. But apparently it loads it in a different way which doesn't give you access to the internals.

    I tested out Loader on an external SWF, and it worked perfectly, but the question was how to use it on an embedded file. I found this blog post, which does exactly what I wanted:

    http://www.8bitrocket.com/2010/2/9/A...-Compile-Time/

    You just need to embed the SWF as an octet-stream, and load it in as a ByteArray. Very easy, and so far it works perfectly. I have no idea why the embedding in the other way does not give you access to the internals.

  4. #4
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    I have only used Embed in Flex so far and not tried to access anything in a movie. But today I tried and I used the SWFLoader component in Flashbuilder 4. The problem is that the init event, which is triggered when the content is accessible is never fired. That is only fired when the movie is loaded with the load function. Probably in Flash it is similar. Interesting the blog post.
    - The right of the People to create Flash movies shall not be infringed. -

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