Hi,

> I'm instantiating new components and calling addChild() as needed in my container component's
UpdateDisplayList function.

If I hear you right, no this is not the right place to call add child.

You should use commitProperties() override to create and add children in your component.

Say,

someProperty = true; // set somewhere at runtime

public function set someProperty(value:Boolean):void
{
   if (value != _someProperty)
   {
      _someProperty = value
      somePropertyChanged = true;
      invalidateProperties();
   }
}


override protected function commitProperties():void
{
   super.commitProperties();
  
   if (somePropertyChanged)
   {
      if (mySlider)
      {
         removeChild(mySlider);
      }

      mySlider = new HSlider();
      ... set up properties
      addChild(mySlider); // updateDisplayList() will be called because addChild() calls invalidateDisplayList()
      somePropertyChanged = false;
   }
}

override protected function updateDisplayList(....
{
   super.updateDisplayList(...

   mySlider.move(...
   mySlider.setActualSize(...
}


This is the correct algorithm for creating new children during runtime if properties change that are relvant to the HSlider being added dynamically at runtime.

Peace, Mike









On 8/17/06, thunderstumpgesatwork <[EMAIL PROTECTED]> wrote:


Hi all,

I'm running into Flex 2 Release error with Slider (HSlider to be
exact). The "null reference exception" happens when there are no
thumbs. See the source and exception traces below. On line 1480 it
checks the number of thumbs and correctly handles a null 'thumbs'
array. However, if thumbs turns out to be null, or the number of
thumbs is 0, we get the null reference exception on line 1483 (which
doesn't do the same check as was done on 1480).

I'm probably partially at fault for all of this, as I'm trying to
dynamically create instances of components and add them to the UI at
runtime. Is there some precautions that I need to take to ensure
everything is initialized properly? I'm instantiating new components
and calling addChild() as needed in my container component's
UpdateDisplayList function. Does this need to be handled elsewhere?

// -- from Slider.as --
1478: var isHorizontal:Boolean = (_direction ==
SliderDirection.HORIZONTAL);
1479: var numLabels:int = labelObjects ? labelObjects.numChildren : 0;
1480: var numThumbs:int = thumbs ? thumbs.numChildren : 0;
1481: var trackMargin:Number = getStyle("trackMargin");
1482: var widestThumb:Number = 6;
1483: var firstThumb:SliderThumb = SliderThumb(thumbs.getChildAt(0));

// Exception Trace
TypeError: Error #1009: Cannot access a property or method of a null
object reference.
at
mx.controls.sliderClasses::Slider/mx.controls.sliderClasses:Slider::updateDisplayList()[C:\dev\GMC\sdk\frameworks\mx\controls\sliderClasses\ Slider.as:1483]
at
mx.core::UIComponent/validateDisplayList()[C:\dev\GMC\sdk\frameworks\mx\core\UIComponent.as:5672]
at
mx.managers::LayoutManager/mx.managers:LayoutManager::validateDisplayList()[C:\dev\GMC\sdk\frameworks\mx\managers\LayoutManager.as:594]
at
mx.managers::LayoutManager/mx.managers:LayoutManager::doPhasedInstantiation()[C:\dev\GMC\sdk\frameworks\mx\managers\LayoutManager.as:664]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at
mx.core::UIComponent/mx.core:UIComponent::callLaterDispatcher2()[C:\dev\GMC\sdk\frameworks\mx\core\UIComponent.as:7789 ]
at
mx.core::UIComponent/mx.core:UIComponent::callLaterDispatcher()[C:\dev\GMC\sdk\frameworks\mx\core\UIComponent.as:7732 ]




--
What goes up, does come down. __._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to