Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6331373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:03:08+00:00 2026-05-24T18:03:08+00:00

I’m trying to replace instances created by dragging and dropping into a MovieClip through

  • 0

I’m trying to replace instances created by dragging and dropping into a MovieClip through Flash’s IDE with actual classes so I can add them to a game loop and have them as actual entities. In other words, I’m trying to create a streamlined way to allow developers to visually add their entities to a platforming engine I’m working on.

This is my third attempt at it and I’m completely stuck.

The code below loops through a movieclip that contains an exported symbol with a class linked to it named MyEntity. However, it loses its extension to BaseClass and thus doesn’t move when compiled.

It inherits: MovieClip > BaseClass > MyEntity. However when compiled with the IDE it ignores BaseClass and just does MovieClip > MyEntity.

My code is designed to find and store the position of MyEntity, remove it from the container movieclip, add a brand new instance of it (with the base being proper) then set that new instance to the same position of the original.

for ( var i:int = 0; i < LayerInIDE.numChildren; i++ )
{
    // first we want to get all the display objects in the layer
    // these are objects that were placed from within the Flash IDE (ie. dragged and dropped into the MovieClip
    var original:DisplayObject = LayerInIDE.getChildAt( i );            

    // we want to get the class of the display object so we can recreate it as a specific entity class that it 
    var originalName:String = getQualifiedClassName( original );
    var originalClass:Class = getDefinitionByName( originalName ) as Class;

    // debug trace, see output below
    trace( originalName, originalClass, originalClass is BaseClass );

    // filter out movieclips
    if ( originalClass != MovieClip )
    {
        // remove the original
        LayerInIDE.removeChild( original );

        // recreate the class with the correct extension
        var newEnt = originalClass();
            newEnt.x = original.x; newEnt.y = original.y;
        LayerInIDE.addChild( newEnt );
    }
}

This does not work.

It outputs Game.entities::MyEntity [class MyEntity] false. MyEntity is a proper class and DOES extend from BaseClass. However, the issue is the IDE weirdly removes the reference to the base class – as if MyEntity never had a base class. I cannot seem to recreate it as getting the reference to the class also returns that MyEntity never had a BaseClass. However, if I type in var newEnt = MyEntity(); instead of getting the class name through getDefinitionByName it works normally and extends from BaseClass.

I need it to extend from BaseClass as that is the main class all entities in my game engine require to use.

Any ideas? Or is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:03:10+00:00Added an answer on May 24, 2026 at 6:03 pm

    After much tinkering and generally breaking Flash, I got the solution to my problem. Thanks to Stephen Braitsch‘s help for getting me in the right direction.

    Okay, so this solution is a little complicated (and hacky) but it gets around the issues I was previously discussing.

    First you’ll need the main function that scans through all the display objects in a specific movieclip. I’ve named mine LayerInIDE.

    There’s two functions needed. ReplaceEnts and Recreate. ReplaceEnts scans through all the objects and determines if they extend from BaseClass. If they do, it goes ahead and throws them through Recreate. Recreate takes the original class and position and recreates the class allowing us to access the asset during runtime properly.

    import Game.entities.MyEntity;
    import Game.entities.BaseClass;
    import Game.entities.Layer;
    
    var LayerInIDE:Layer = new Layer();
    stage.addChild( LayerInIDE );
    
    ReplaceEnts( LayerInIDE );
    
    function ReplaceEnts( layer:Layer ):void
    {
        for ( var i:int = 0; i < layer.numChildren; i++ )
        {
            // Get the display object.
            var original:DisplayObject = layer.getChildAt( i );
    
            // Make sure we're only doing this to objects that extend from BaseClass
            if ( original is BaseClass )
            {
                // Get the original class
                var originalName:String = getQualifiedClassName( original );
                var originalClass:Class = getDefinitionByName( originalName ) as Class;
                // Remove the original
                layer.removeChild( original );
    
                // Recreate it with the original class
                // Make sure we keep the original position and rotation.
                var bc = Recreate( originalClass, original.x, original.y, original.rotation );
                layer.addChild( bc );
    
                // Test functions
                trace( bc ); // outputs: [object MyEntity]
                bc.TestFunc(); // outputs: test
                bc.BaseTest(); // outputs: base
            }
        }
    }
    
    // This is the core function that does all the work.
    // It recreates the entity with the proper class and sets it to its original position.
    function Recreate( entClass:Class, iPosX:int = 0, iPosY:int = 0, iRot:int = 0 ):BaseClass
    {
        var newEnt:BaseClass = new entClass();
        newEnt.x = iPosX; newEnt.y = iPosY;
        newEnt.rotation = iRot;
    
        return newEnt;
    }
    

    Then the BaseClass contains:

    package Game.entities
    {
        import flash.display.MovieClip;
    
        public class BaseClass extends MovieClip
        {
            // The example function as mentioned above in the ReplaceEnts function.
            public function BaseTest():void
            {
                trace( "base" );
            }
        }
    }
    

    Once that is all set, we’ll need to also make the MyEntity class:

    package Game.entities
    {
        public class MyEntity extends BaseClass
        {
            // The example function as mentioned above in the ReplaceEnts function.
            public function TestFunc():void
            {
                trace( "test" );
            }
        }
    }
    

    Just a final note, Games.entities.Layer is just a simple MovieClip. I only created my own class for it for organization purposes in this.

    The solution here is simple. When a user drags an object that extends from BaseClass into a layer, the function runs on start up and replaces the asset with the proper class and allows for an entity manager to take over and handle the asset appropriately. It allows for what I wanted to achieve, an IDE-powered level editor that automatically does all the work placing the entities where you want them.

    Thanks for all the help guys.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.