2 Replies Latest reply on Mar 22, 2008 1:59 AM by ctzn99

    Default Properties

    ctzn99 Level 1
      Ok, I know how to create a default property in a custom .as class so that when i use that class in mxml i can use the default property but... does anyone know how (or if) i can set a default property when i make an mxml component so that i can then use the component, with a default property in my application mxml.

      I tried this:
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Panel xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300" title="{panelLabel}">
      <mx:Script>
      <![CDATA[
      [DefaultProperty("PanelLabel")]

      [Bindable] private var panelLabel:String = "Unnamed";

      public function set PanelLabel(newLabel:String):void
      {
      this.panelLabel = newLabel;
      }

      public function get PanelLabel():String
      {
      return this.panelLabel;
      }
      ]]>
      </mx:Script>
      </mx:Panel>

      And hoped it would work with this:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">
      <local:MyPanel>Test</local:MyPanel>
      </mx:Application>

      But no go. I get: "Initializer for 'MyPanel': values of type MyPanel cannot be represented in text.

      If I can't do it from the mxml component it's easy enough to a) first create the component and then b) make an as3 class that inherits from the component that has the defaultProperty meta tag but the only purpose of that class would be to add a default property to the component. It seems logical to me that you should be able to add the default property directly to the component but im stumped.