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.
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.
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.
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
Good find Chafic. I remember we talked about this a while back. Glad you figured it out. That is useful.
Yeah, several of us out there have been wondering this. I was hoping you would spend the time first and figure it out
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
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
Hello there,
Iwas browsing the web and found this blog. Some interesting quotes. Keep them coming!
Alice
puranol
Hello there,
Iwas browsing the web and found this blog. Some interesting quotes. Keep them coming!
Alice
cheap secured loan
Nice siteGod knows
Bye!
Jill Jones
Welcome Home Everyone Home
Cya
Max
Hi Guys
Thanks for taking the time posting. MSN have finally launch blogs, what was with the delay?
Call Centre Metrics
Cya
Bruce