flex-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mark goldin <markzolo...@gmail.com>
Subject Re: Send parameter to mxml constructor
Date Fri, 27 Sep 2013 15:38:37 GMT
Well according to the docs Flex calls the IMXMLObject.initialized() method
after it initializes the properties of the component.
Isn't it too late for what I need?  Is this the sample you are referring to:

<?xml version="1.0"?>
<!-- mxmlAdvanced/myComponents/ObjectComp.mxml -->
<fx:Object xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark"
    xmlns:mx="library://ns.adobe.com/flex/mx"
    implements="mx.core.IMXMLObject">

    <fx:Script>
        <![CDATA[

            // Implement the IMXMLObject.initialized() method.
            public function initialized(document:Object, id:String):void {
                trace("initialized, x = " + x);
            }
        ]]>
    </fx:Script>

    <fx:Declarations>
        <fx:Number id="y"/>
        <fx:Number id="z"/>
        <fx:Number id="x"/>
    </fx:Declarations>
</fx:Object>


On Thu, Sep 26, 2013 at 10:24 PM, Alex Harui <aharui@adobe.com> wrote:

> Hi Mark,
>
> That is a limitation of MXML.  If you have an AS class that is based on
> UIComponent, you are encouraged to use the lifecycle methods like
> invalidateProperties/commitProperties instead of doing work off the
> constructor.  If you have an AS class not based on UIComponent, a common
> pattern is to implement IMXMLObject and do all of the work in the
> initialize method so it can be used in MXML, and then when instantiating
> in AS, you will do:
>
>         var _myClass_mxml:MyClass_mxml = new MyClass_mxml();
>         _myClass.initialize(document, "_myClass");
>
> -Alex
>
> On 9/26/13 7:14 PM, "mark goldin" <markzolotoy@gmail.com> wrote:
>
> >No, that does not work because what I am instantiating is an mxml class
> >that is based on MyClass:
> >MyClass_mxml:
> ><ns:MyClass>
> >...
> ></ns:MyClass>
> >
> >and then in AS:
> >var _myClass_mxml:MyClass_mxml = new MyClass_mxml(); This will not take a
> >parameter to a  constructor.
> >
> >
> >On Thu, Sep 26, 2013 at 8:55 PM, Mark Kessler
> ><kesslerconsulting@gmail.com>wrote:
> >
> >> Oh I see your using AS to create an instance of it.
> >>
> >> This would work for accessing that property...
> >> var newMyClass:MyClass = new MyClass()
> >> newMyClass.myProperty = object being passed.
> >>
> >>
> >> But since your using AS you could pass it in the constructor now.
> >>
> >>     public class MyClass
> >>     {
> >>         //Constructor
> >>         public function MyClass (myProp:Object)
> >>         {
> >>             //init stuff using whatever you passed.
> >>         }
> >>     }
> >>
> >> var newMyClass:MyClass = new MyClass(My prop or object or whichever
> >>matches
> >> your needs.)
> >>
> >>
> >>
> >> -Mark
> >>
> >>
> >> On Thu, Sep 26, 2013 at 9:01 PM, mark goldin <markzolotoy@gmail.com>
> >> wrote:
> >>
> >> > That is not exactly what I have. Yes, I too have an mxml class based
> >>on
> >> > another AS class. But I am creating an instance of my mxml class like
> >> this:
> >> > var newMyClass:MyClass = new MyClass();
> >> > So, how can I pass a value for myProperty to newMyClass? My
> >>understanding
> >> > as soon as var newMyClass:MyClass = new MyClass(); executes all
> >>children
> >> on
> >> > newMyClass will be created but I need to have myProperty before that.
> >> >
> >> >
> >>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message