PDA

View Full Version : Flex creation order confusion


AshMcConnell
06-25-2009, 07:26 PM
Hi Folks,

I have a LinkBar with an associated ViewStack. Each item in the view stack is of a base class "SetupBase" (this is for a car setup UI). The SetupBase class has a onFocus and onLoseFocus method on it. I have set up an itemClickEvent to call "onLoseFocus" on the last item and "onFocus" on the new item: -

public function chooseSubMenu(event:ItemClickEvent):void{
var newItem:SetupBase = (viewstack1.selectedChild as SetupBase)
newItem.onFocus();
if (lastSelected != null){
lastSelected.onLoseFocus();
}

lastSelected = newItem;
}

On one of my object in the viewstack (BrakeSetup derived from SetupBase) I am modifying a Slider object's value in the "onFocus" method.

I also have a change event on the slider. This makes calls to save the value of the slider to file (using ExternalInterface)

The problem is that the change event is being fired after the onFocus event with the original value of the slider and not the value that was changed in onFocus

When I do a debug I see the stack: -

Main Thread (Suspended)
garagemenus::BrakeSetup/brakeBalanceChange
garagemenus::BrakeSetup/__brakeBalanceSlider_change
flash.events::EventDispatcher/dispatchEventFunction [no source]
flash.events::EventDispatcher/dispatchEvent [no source]
mx.core::UIComponent/dispatchEvent
mx.controls.sliderClasses::Slider/setValueAt
mx.controls.sliderClasses::Slider/commitProperties
mx.core::UIComponent/validateProperties
mx.managers::LayoutManager/validateProperties
mx.managers::LayoutManager/doPhasedInstantiation
Function/http://adobe.com/AS3/2006/builtin::apply [no source]
mx.core::UIComponent/callLaterDispatcher2
mx.core::UIComponent/callLaterDispatcher


Is there a way to ensure everything is properly created / initialised beforehand? I tried calling initialise() in the onFocus() and setting creationPolicy="all" but it doesn't seem to have worked

Thanks for your help
All the best,
Ash