A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] Subclassing, library items and getDefinitionByName

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    3

    resolved [RESOLVED] Subclassing, library items and getDefinitionByName

    I've a reasonably complex problem, and I apologise in advance for the essay post, but I believe all the information is necessary.

    Just a little background to start with:

    I've recently inherited an AIR project, which is basically a widget that displays product images and static content (contact details etc) on the desktop.

    The original project was developed in CS4/AS3, and has been published and works fine. Since then, the original developer has gone overseas and I've been hired to make new versions of this widget, UI reskins, different products, etc. I work in CS3, so I've had the original Flash authoring file saved down, gotten Flash CS3 to be able to publish for the AIR runtime, and found the relevant AIR classes that I need. This has all gone smoothly.


    The problem I'm having, is that there seems to be some strange way that the original developer has linked the library items to their relevant classes, and I'm trying to unravel this.

    I'm going to use the clip called windowApplication as my example.

    In the library, there is a movie clip symbol called 'windowApplication'. In its linkage settings, its class is set to 'windowApplication', and its base class 'com.aca.windows.Application'.

    The Application class extends the MovieClip class.

    However, when I test the app, I get compiler errors
    '5000: The class 'com.aca.windows.Application' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.'
    '1151: A conflict exists with definition SectionBackground in namespace internal.'
    (SectionBackground is the first variable declaration in the Application class. Commenting it out makes this error change to the second variable declaration).


    I can remove this error by changing the class of the 'windowApplication' symbol to 'Application' and setting the base class to 'flash.display.MovieClip', however that doesn't seem to instantiate the class properly. The symbol appears onscreen, but none of its instantiating functions are called.

    The windowApplication object is instantiated using a getDefinitionByName call. I've had a google and looked around various forums, and I've seen suggestions that classes used in getDefinitionByName need to also have a fake instantiation so that they're compiled in Flash. I've tried this but it makes no difference.


    It seems to me that the getDefinitionByName call is working properly, as it does bring up the correct symbol - but only when the base class is flash.display.MovieClip.


    Other information that might either help or send you as crazy as it is me:
    I had another movie clip, called sectionMain, that also had this problem. Its original class was 'sectionMain' and its base class is 'com.aca.sections.Main'. It, too, threw a compiler error 5000. I changed the symbol's class to 'Main' and the base class to 'flash.display.MovieClip', when testing the app, this brought up the symbol. When I changed it back to the original settings, it worked fine, the object was called properly and I could interact with it. However, when the errors with the Application class are thrown, I also get the 5000 error for the Main class - without having changed anything.

    When I change the class of the windowApplication symbol to 'Application' instead of 'windowApplication', I get a warning that Flash can't find the class and will create one at runtime.

    I've been going around in circles with this problem. Can anyone shed any light on what might be going on here - is there a reason why the developer might have set the symbols/classes up in this way, or is there something that I'm missing here?
    Last edited by Seakla; 08-29-2009 at 01:19 AM. Reason: Original post cut off

  2. #2
    Member
    Join Date
    Jul 2005
    Location
    Brisbane, Australia
    Posts
    66
    Go to Publish Settings > Flash > ActionScript 3.0 Settings and turn off "Automatically declare stage instances".

  3. #3
    Junior Member
    Join Date
    Aug 2009
    Posts
    3

    Thumbs up

    You sir, have made my weekend - after changing that, then adding in the declarations for the movie clips that were on the stage/in the library symbols, this application is FINALLY working!!!

    Would you perhaps be able to explain why this fixed it? Is it some difference between CS3 and CS4, or was it something I missed?

    Thank you VERY much.

  4. #4
    Member
    Join Date
    Jul 2005
    Location
    Brisbane, Australia
    Posts
    66
    No problem, I've seen this problem before so it was easy to spot.

    That option i mentioned above creates variable declarations for stage instances in your class files. Since you already created variable declarations for your instances, when flash tries to create them it gets into trouble. This is why commenting out SectionBackground caused the error to change to the next stage instance variable.

    The 5000 error just appears because the Application Class failed to compile, so fixing the variable declaration stuff makes it go away.

  5. #5
    Junior Member
    Join Date
    Aug 2009
    Posts
    3
    Good to know that it was a more or less obscure issue I'd have felt terrible if it was something simple!

    Thanks again for your help.

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