views:

286

answers:

2

Hi there.

I'm trying to propagate an assignment to the data parameter of a sub-component through it's parent component's setter. Like this:

<CustomComponent
     xmlns:mx="http://www.adobe.com/2006/mxml"
     xmlns="components.*"
    >
    <mx:Script>
     <![CDATA[
      public override function set data(val:Object):void
      {
       super.data = val;

       subComponent.data = val; //ref #1
      }
     ]]>
    </mx:Script>
    <CustomSubComponent id="subComponent"
     />
</CustomComponent>

When I ran my application, the sub-component never received its data. When debugging and stepping to the line marked "ref #1", the debugger jumps out of the method and continues on to something else as if the method was complete. It seems like some exception or error was thrown but the console gives no indication of what is wrong with this assignment.

Am I doing something stupid here? It seems pretty straight forward.

Environment: This is using Flex SDK 3.2, with the Flex Builder 3 plugin for Eclipse on Windows, with Flash 9 Debug ver. for IE7.

Note: With this particular example I'm trying to avoid Binding on purpose. I mean, why can't I manually push the data to the sub-component rather than binding it?

A: 

What Components are your custom component and sub component based on ? What do they extend ?

I've tried a basic example extending HBox and VBox and all went fine.

You can see the result here, source view enabled.

I'm guessing I had no issues because I'm extending components that are added to the display list so it's part of they're life cycle to check with parents for measurements/data/etc.

Hope it helps

George Profenza
All my custom components are Canvases.
DyreSchlock
Do you really need the absolute positioning ? I'm guessing the hierarchy doesn't get updated in the same way for absolute containers as opposed to relative ones. You should be able to override the way that is updated. I will have a look later at home if it helps.
George Profenza
+1  A: 

Flex suppresses errors inside of data setters, because stuff is frequently null. The problem is probably that your subcomponent is not initialized when set data is called. If you really can't use binding (the easy and clean way), then you should delay setting the data of the subcomponent until it is initialized with invalidateProperties / commitProperties.

In the data setter, call invalidateProperties() and set a flag saying they've changed.

Override commitProperties (don't forget to call super), check the flag, and if it's true, set the subcomponent's data.

If your commitProperties block never gets called, try invalidateProperties on creationComplete.

Sean Clark Hess