Skip navigation
Currently Being Moderated

createDynamicPartInstance returns null

May 4, 2011 10:14 AM

I'm learning how to create custom components and started by developing a test component that correctly creates dynamic parts.  So far, so good.  Then I tried to move that component into my real project, but when I run it there, createDynamicPartInstance always returns null (which obviously doesn't happen in the test component).  I've gone over and over the code, but can't find any differences, aside from the test components having a slightly different name.


Can anyone suggest what the difference may be?  I'm at a loss.





Here are the relevant parts of the real component that isn't working correctly:


package com.leadingstep.components
    import com.leadingstep.skins.DisplaySentenceSkin;
    import mx.collections.*;
    import mx.core.IFactory;
    import spark.components.HGroup;
    import spark.components.supportClasses.SkinnableComponent;
    public class DisplaySentence extends SkinnableComponent
        [SkinPart(required="true",type="com.leadingstep.components.SentenceWo rd")]
        public var line1Words:IFactory;
        [SkinPart(required="true",type="com.leadingstep.components.SentenceWo rd")]
        public var line2Words:IFactory;
        public var line1:HGroup;
        public var line2:HGroup;


        public function DisplaySentence()
            setStyle("skinClass", DisplaySentenceSkin);


        protected function createLine1Words():void {
            for (var i:uint=0; i < 20; i++) {
                trace("create line 1 word " + i);
                 if (createDynamicPartInstance("line1Words") == null) {
                     trace("create dynamic returned null");
                 } else {
                     trace("create dynamic did not return null");




And the skin:


<s:Skin xmlns:fx=""
        xmlns:mx="library://" xmlns:components="com.leadingstep.components.*">
    <!-- host component -->
    <!-- SkinParts
    name=line1Words, type=mx.core.IFactory, required=true
    name=line2Words, type=mx.core.IFactory, required=true
    name=line2, type=spark.components.HGroup, required=true
    name=line1, type=spark.components.HGroup, required=true
        <fx:Component id="line1Words" >
            <components:SentenceWord skinClass="com.leadingstep.skins.SentenceWordSkin"/>
        <fx:Component id="line2Words" >
            <components:SentenceWord skinClass="com.leadingstep.skins.SentenceWordSkin"/>
        <s:HGroup id="line1"/>
        <s:HGroup id="line2"/>

  • Currently Being Moderated
    Oct 20, 2011 2:39 PM   in reply to drrevis

    @drrevis Thanks for posting your solution. That helped me figure-out what was going wrong with my dynamic part instances.

    Mark as:
  • Currently Being Moderated
    Dec 3, 2013 7:07 PM   in reply to drrevis

    Hi Drrevis,

    You are right, we should not rely on the partAdded to add the Dynamic part. From my experience, this process should happen in createChildren() (once all the skin parts have been added to the stage).





    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points