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

  • Home
  • SEARCH
  • 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 7218431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:28:53+00:00 2026-05-28T21:28:53+00:00

I’m writing an application that uses extendable UI elements, whose precise implementation is determined

  • 0

I’m writing an application that uses extendable UI elements, whose precise implementation is determined at run-time using configuration. So for example, I want to show a list of items, which – depending on the configuration – may be shown as bulleted list, a numbered list, a two column list, etc. The containing application knows nothing about the specific implementation except that it is a type that supports the method call setItems(items:Array):void.

So I have set up a base class, for example:

package my.stuff {
    public class BaseList extends MovieClip {
        protected var m_items:Array;
        public function BaseList() {
            m_items = new Array();
        }
        public function setItems(items:Array):void {
            for (var i:int = 0; i < items.length; i++)
                m_items.push(items[i]);
        }
    }
}

And then I have create a specialized implementation that does, for example, two column list:

package my.stuff {
    public class TwoColumnList extends BaseList {
        protected var m_columns:Array;
        public function TwoColumnList() {
            super();
            m_columns = new Array();
            m_columns.push(new Array());
            m_columns.push(new Array());
        }
        public override function setItems(items:Array):void {
            for (var i:int = 0; i < items.length; i++) {
                m_items.push(items[i]);
                m_columns[i%2].push(items[i]);
            }
        }
    }
}

Now the UI itself is done in Flash Professional as an FLA with class TwoColumnList as the “document class”. I compile the FLA (“publish”) to the target SWF, then I try to load it into the application. Normally I’d expect this to work like so:

public function startLoading(implURL:String):void) {
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.INIT, doneLoadingImpl);
    loader.load(new URLRequest(implURL));
}

public function doneLoadingImpl(e:Event) {
    var info:LoaderInfo = e.target as LoaderInfo;
    var impl:DisplayObject = info.content;
    m_containerClip.addChild(impl);
    var listImpl:BaseList = impl as BaseList;
    impl.setItems(m_allItems);
}

Except this doesn’t work – the addChild() works fine but the cast to BaseList results in null (not an exception – just null). I can cast impl to MovieClip just fine, and I can also cast it directory to TwoColumnList, after which it casts-up nicely to BaseList, like this:

...
var listImpl:BaseList = impl as TwoColumnList;
...

So that works, but it really defeats the purpose of the whole exercise – which is to not know ahead of time the specific UI implementations that may be created in the future.

I read somewhere about doing info.applicationDomain.getDefinition, but I can’t say it does any effect whatsoever.

I’m not an ActionScript developer in my day to day job, I’ve just been called to help out with some project whose main developer is no longer with the company, and I’m stumped – any help will be appreciated.

  • 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-28T21:28:54+00:00Added an answer on May 28, 2026 at 9:28 pm

    Your problem is most likely related to the classes loading into different application domains. The type cast returns null, if the object is not a subclass of the class you are casting to – and it seems you have two versions of BaseList “competing” with each other.

    If this is the case, you can work around it by explicitly loading the SWF into the same application domain as the main one:

     var ldrContext : LoaderContext = new LoaderContext ( false, ApplicationDomain.currentDomain );
     var loader:Loader = new Loader();
     loader.contentLoaderInfo.addEventListener(Event.INIT, doneLoadingImpl);
     loader.load(new URLRequest(implURL), ldrContext );
    

    However, especially when loading external content, you should really be using interfaces. Keeping the implementations decoupled is exactly what they were invented for. Check out this blog page, it explains why you should use interfaces when loading external files (there also is a link to more fundamental info about interfaces), and incidentally, the author seems to have had a problem similar to yours… 😉

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words

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.