15
Jan
04

“import” is required for component meta-data

The documentation says the “import” statement in Flash is just a convenience for programmers so we don’t have to specify a fully-qualified class name in our code repeatedly. The “import” statement isn’t supposed to have any real effect on the generated code. It’s supposed to be optional.

Turns out when developing components, “import” is required!

Last night Jonathan Kaye asked a question on Flashcoders that has been on my mind for a while but never spent time on to figure out its behavior. The issue involves sub-classing components that contain Metadata Tags. I never was sure, but for some reason sometimes it would work and other times it would not. If you take these two classes as an example:

class SuperClass
{
[Inspectable]
public var superProp;
};

class SubClass extends SuperClass
{
[Inspectable]
public var subProp;
};

The SubClass extends SuperClass, as such the SubClass receives all implementation from the parent class–In this case it is the superProp property. If you have worked on any components, you would usually expect all Metadata Tags (like Inspectable in this case) to also carry over to the children. If you read the documentation provided by Macromedia, it states that the Metadata Tags indeed are inheritable and that it is pretty seamlessly handled by the IDE. As it turns out though, if you tried to build a component using the code above, superProp’s Inspectable Metadata Tag is not inherited.

Image of Properties Panel:

I also noticed that sometimes it worked for me and sometimes it did not and was not sure what caused this. So after sifting through code and some troubleshooting, I tracked down the issue to one line of code, the line that imported the parent class. It turnes out that the import statement is required for the IDE to inspect the parent class for any Metadata Tags. So if we take the previous code and add one line to the SubClass.

import SuperClass; //this is the added line

class SubClass extends SuperClass
{
[Inspectable]
public var subProp;
};

Updated Properties Panel:

The IDE will correctly parse through the Metadata Tags. I hope someone finds this useful as I didn’t see it mentioned anywhere and it definitely is not intuitive.


12 Responses to ““import” is required for component meta-data”


  1. 1 JesterXL Jan 15th, 2004 at 3:53 pm

    Interesting… In the past, I either did an #include, or just included the class right there above it; similiar to how the old FUIComponent did it with FStyleFormat (gross).

    Pretty sweet to have the correlation clearly explained, though. I just assumed that you had to do import, but I wasn’t doing much with inspectable. Phat-a-licious.

  2. 2 Julian Jan 15th, 2004 at 5:11 pm

    That’s pretty handy but I still prefer to use the mergeClipParameters command. Only for the reason that I might not want all of the Inspectable properties of the super class to appear in the Inspector. Otherwise that is a great solution.

  3. 3 Chafic Kazoun Jan 15th, 2004 at 5:12 pm

    Julian, you mentioned the “mergedClipParamaters command”. That actually is related to processing parameters at runtime and is not related to metadata tag inheritance. I’ll try to clarify

    1. If you want your sub-class to inherit any Metadata tag, you have to use import. If you don’t, the IDE will not pick up the Metadata tags at all no matter what you do with mergeClipParamaters/etc
    2. You mentioned the need to filter the the inspectable tags. If you want to filter the Metadata Tags, you would use the [InspectableList] MetaData Tag
    3. clipParamaters is used by the architecture at runtime. It is not used by the IDE to identify the inspectable properties

  4. 4 Keith Peters Jan 15th, 2004 at 8:37 pm

    Good find Chafic. I remember we talked about this a while back. Glad you figured it out. That is useful.

  5. 5 Chafic Kazoun Jan 15th, 2004 at 9:36 pm

    Yeah, several of us out there have been wondering this. I was hoping you would spend the time first and figure it out :)

  6. 6 Peter Hall Jan 19th, 2004 at 11:16 am

    Thanks! I had given up tearing my hair out and decided that it just wasn’t going to work…

    Looks like I’m buying the first round in Star City ;-)

  7. 7 Jonathan Kaye Jan 20th, 2004 at 11:25 pm

    Great, Chafic!

    I figured that the MergeClipParameters was a FOL because I saw it in my quick dive into MM’s component code. Good thing you solved this–I don’t have Peter’s luxury of having much hair to tear out anymore…

    -jonathan

  8. 8 puranol Oct 29th, 2004 at 12:16 pm

    Hello there,

    Iwas browsing the web and found this blog. Some interesting quotes. Keep them coming!

    Alice
    puranol

  9. 9 cheap secured loan Nov 2nd, 2004 at 5:27 pm

    Hello there,

    Iwas browsing the web and found this blog. Some interesting quotes. Keep them coming!

    Alice
    cheap secured loan

  10. 10 jill jones Nov 22nd, 2004 at 1:56 am

    Nice siteGod knows

    Bye!
    Jill Jones

  11. 11 Max Power Dec 3rd, 2004 at 5:31 am

    Welcome Home Everyone Home

    Cya
    Max

  12. 12 Call Centre Metrics Dec 3rd, 2004 at 7:35 pm

    Hi Guys

    Thanks for taking the time posting. MSN have finally launch blogs, what was with the delay?
    Call Centre Metrics

    Cya
    Bruce

Comments are currently closed.