Announcement

Collapse
No announcement yet.

Scaleform 4/AS3 - Attaching & Removing Movie Clips from UnrealScript

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Scaleform 4/AS3 - Attaching & Removing Movie Clips from UnrealScript

    In ActionScript 2, movie clips are added to the stage from the Library via AttachMovie() and removed via removeMovieClip().

    UnrealScript AS2 Examples:
    Code:
    RootMC.AttachMovie("MouseContainer", "MouseCursor"); // argument1 = Flash symbol Identifier; argument2 = new instance name
    MouseContainer.Invoke("removeMovieClip", args);

    Scaleform 4/AS3


    In Scaleform 4/ActionScript 3, there are some slight differences. First off, in AS3, AttachMovie() has been replaced with addChild(), and removeMovieClip() has been replaced with removeChild(). However, for simplicity, the Scaleform DirectAccess API still uses AttachMovie() in place of addChild(). The difference is that the first argument of AttachMovie() is now the Class name of the Flash Symbol, and not its Identifier (which is an AS2 convention).

    So, to add a movie clip in Scaleform 4/AS3, you still use:

    Code:
    RootMC.AttachMovie("MouseCursorContainer", "MouseContainerMC"); // argument1 = Flash AS3 class name; argument2 = new instance name
    To execute removeChild() however requires adding a new UnrealScript class which provides a way to call removeChild() passing it a GFxObject (or movie clip):

    Code:
    class GFxDisplayObject extends GFxObject;
    
    function RemoveChild(GFxObject childObject)
    {
        ActionScriptVoid("removeChild");
    }
    With this new class, we can then use a line similar to the following example to remove a movie clip:

    Code:
    GFxDisplayObject(MouseContainerMC.GetObject("parent",class'GFxDisplayObject')).RemoveChild(MouseContainerMC);
    In AS3, all Display Objects have a 'parent' property which points to the parent of that object. So, we get the parent of MouseContainerMC, which is the stage/root, and cast it as a GFxDisplayObject (our new class). Then we are able to use RemoveChild() from that class, passing it MouseContainerMC as the object to be removed.

    #2
    Ths a lot,it's very helpful!

    Comment


      #3
      Having a problem with this... basically I want to create a minimap that pops up some directional cones that determines enemies' firing direction (we get to know their direction when they fire at us, or at least firing closely to us

      The movieclip should appear, then fade away and gone, get deleted to save memories, it won't show up at all, in my case. I use AS3 for this

      http://forums.epicgames.com/threads/...roblem-Minimap

      Comment

      Working...
      X