Thanks for the response. I actually used to use that exact technique to handle the sliding. The only problem with that way is that since you're listening for the change, the new tab will appear briefly before the animation. It will slide in properly, but that flicker irritated me. If there's a good way to fix that problem, then I could abandon my attempts at overriding selected index.
I am eventually calling super.selectedIndex, it's just not until the entire transition has completed. --- In [email protected], Alex Harui <aha...@...> wrote: > > Try the following. It doesn't use creationComplete, but I might be missing > something. One key change is that your selectedIndex override never called > super.selectedIndex so the viewstack didn't really know what was going on. > This version reacts to the "change" event instead. > > package > { > import flash.display.DisplayObject; > import flash.events.Event; > import flash.events.TimerEvent; > import flash.utils.Timer; > > import mx.containers.ViewStack; > import mx.core.Container; > import mx.core.mx_internal; > import mx.effects.Move; > import mx.events.EffectEvent; > import mx.events.IndexChangedEvent; > use namespace mx_internal; > > > public class SlidingViewStack extends ViewStack > { > public static const LEFT_RIGHT:String = > "leftRight"; > public static const TOP_BOTTOM:String = > "topBottom"; > > private var _direction:String = LEFT_RIGHT; > private var _lastIndex:int = -1; > private var _newIndex:int; > > public function SlidingViewStack() > { > addListeners(); > } > > public function set > direction(direction:String):void > { > _direction = direction; > } > > public function get direction():String > { > return _direction; > } > > private function addListeners():void > { > addEventListener("change", > selectedIndexChanged); > } > > private function > selectedIndexChanged(event:IndexChangedEvent):void > { > _newIndex = event.newIndex; > _lastIndex = event.oldIndex; > if(event.newIndex != > event.oldIndex && event.newIndex >= 0 && event.oldIndex >= 0) > { > > slideTabs(event.oldIndex, event.newIndex); > } > } > > private function > slideTabs(oldIndex:int,newIndex:int):void > { > var oldChild:DisplayObject = > getChildAt(oldIndex); > var newChild:DisplayObject = > getChildAt(newIndex); > > var oldMove:Move = new > Move(oldChild); > var newMove:Move = new > Move(newChild); > > if(oldIndex > newIndex) > { > //Moving old > Tab in the direction specified : down through bottom or out through right > if(_direction > == TOP_BOTTOM) > { > > oldMove.yTo = oldChild.height + 100; > > newChild.y = -oldChild.height; > > newMove.yTo = 0; > } > else > if(_direction == LEFT_RIGHT) > { > > oldMove.xTo = oldChild.width + 100; > > newChild.x = -oldChild.width; > > newMove.xTo = 0; > } > } > else > { > //Moving old > Tab in the direction specified : out through top or out through left > if(_direction > == TOP_BOTTOM) > { > > oldMove.yTo = -oldChild.height; > > newChild.y = oldChild.height + 100; > > newMove.yTo = 0; > } > else > if(_direction == LEFT_RIGHT) > { > > oldMove.xTo = -oldChild.width; > > newChild.x = oldChild.width + 100; > > newMove.xTo = 0; > } > } > oldChild.visible = true; > newChild.visible = true; > newMove.play(); > > oldMove.addEventListener(EffectEvent.EFFECT_END,childOffScreen); > oldMove.play(); > } > > private function > childOffScreen(event:EffectEvent):void > { > > event.target.removeEventListener(EffectEvent.EFFECT_END,childOffScreen); > event.target.target.visible = > false; > super.selectedIndex = > _newIndex; > } > > } > } > > Alex Harui > Flex SDK Developer > Adobe Systems Inc.<http://www.adobe.com/> > Blog: http://blogs.adobe.com/aharui > > From: [email protected] [mailto:[email protected]] On > Behalf Of dfalling > Sent: Thursday, October 08, 2009 2:47 PM > To: [email protected] > Subject: [flexcoders] Re: Still struggling with creation complete > > > > I've figured out that if I tell the targetChild to invalidate its size, > properties, or display list, then the creationComplete event will be > dispatched for it. However, the view still slides in unrendererd, and only > after sliding all the way in does it render itself. Is there another step I'm > missing to make this item render itself while offscreen, so that when it > comes onscreen it's complete? > > if (targetChild.mx_internal::numChildrenCreated < 0) > { > targetChild.addEventListener(FlexEvent.CREATION_COMPLETE,child_creation,false,0,true); > targetChild.createComponentsFromDescriptors(true); > targetChild.validateNow(); > validateNow(); > mx.core.IInvalidating(targetChild).invalidateSize(); > } > > --- In [email protected]<mailto:flexcoders%40yahoogroups.com>, > "dfalling" <dfalling@> wrote: > > > > Anyone have any ideas? I'm still stumped on this... > > > > My question still boil down to: > > 1) How can I make the component create its children? > > 2) What event can I listen to in order to know when this has completed? > > > > --- In [email protected]<mailto:flexcoders%40yahoogroups.com>, > > "dfalling" <dfalling@> wrote: > > > > > > Here's a sample app with the sliding viewstack. The problems in this > > > example are a) I'm failing to make the new view create itself, b) I don't > > > know what to listen to in the event that I succeed with a). > > > > > > Thanks. > > > > > > http://flexninja.com/examples/slidingViewstack/ > > > > > > --- In [email protected]<mailto:flexcoders%40yahoogroups.com>, > > > Alex Harui <aharui@> wrote: > > > > > > > > The code for a SHOW event runs before things are drawn to the screen. > > > > Sound like something is causing an extra invalidation of the children > > > > so they aren't ready right away. Can you make a simple test case? > > > > > > > > Alex Harui > > > > Flex SDK Developer > > > > Adobe Systems Inc.<http://www.adobe.com/> > > > > Blog: http://blogs.adobe.com/aharui > > > > > > > > From: [email protected]<mailto:flexcoders%40yahoogroups.com> > > > > [mailto:[email protected]<mailto:flexcoders%40yahoogroups.com>] > > > > On Behalf Of dfalling > > > > Sent: Friday, September 18, 2009 2:28 PM > > > > To: [email protected]<mailto:flexcoders%40yahoogroups.com> > > > > Subject: [flexcoders] Re: Still struggling with creation complete > > > > > > > > > > > > > > > > I'm not sure how SHOW would help me as I want to make everything happen > > > > before rendering the child. > > > > > > > > As an experiment, I made the child createComponentsFromDescriptors and > > > > called validateNow() at the viewstack level. I also replaced the event > > > > listener with a timer since I have no idea what event to watch. > > > > > > > > All my attempts to make the child render itself aren't working- even if > > > > the timer waits for several seconds to allow an empty view to render, > > > > it still won't show up until after sliding in. Even once I get this > > > > working, I still won't know what event to listen for to know when the > > > > child's children are created. There's the lovely > > > > childrenCreationComplete event, but that's only dispatched for creation > > > > types of none and queued. > > > > > > > > Here's my current code: > > > > > > > > override public function set selectedIndex(value:int):void > > > > { > > > > _lastIndex = selectedIndex; > > > > > > > > if(value != _newIndex && value != _lastIndex && value >= 0 && > > > > _lastIndex >= 0) > > > > { > > > > _newIndex = value; > > > > var targetChild:Container = getChildAt(value) as Container; > > > > if (targetChild.mx_internal::numChildrenCreated < 0) > > > > { > > > > targetChild.createComponentsFromDescriptors(true); > > > > validateNow(); > > > > _creationTimer = new Timer(3000,1); > > > > _creationTimer.addEventListener(TimerEvent.TIMER,child_creation,false,0,true); > > > > _creationTimer.start(); > > > > return; > > > > } > > > > else > > > > { > > > > slideTabs(_lastIndex,_newIndex); > > > > } > > > > } > > > > } > > > > > > > > private function child_creation(event:Event):void > > > > { > > > > slideTabs(_lastIndex,_newIndex); > > > > } > > > > > > > > --- In > > > > [email protected]<mailto:flexcoders%40yahoogroups.com><mailto:flexcoders%40yahoogroups.com>, > > > > Alex Harui <aharui@> wrote: > > > > > > > > > > I still believe that all children of a viewstack are created no > > > > > matter the creationpolicy. CreationPolicy affects the grandchildren. > > > > > CreationComplete on the child is long gone. Try listening to SHOW as > > > > > well, and call validateNow on the entire viewstack, not just the > > > > > child. Children get their size from the parent. > > > > > > > > > > Alex Harui > > > > > Flex SDK Developer > > > > > Adobe Systems Inc.<http://www.adobe.com/> > > > > > Blog: http://blogs.adobe.com/aharui > > > > > > > > > > From: > > > > > [email protected]<mailto:flexcoders%40yahoogroups.com><mailto:flexcoders%40yahoogroups.com> > > > > > > > > > > [mailto:[email protected]<mailto:flexcoders%40yahoogroups.com><mailto:flexcoders%40yahoogroups.com>] > > > > > On Behalf Of dfalling > > > > > Sent: Friday, September 18, 2009 12:09 PM > > > > > To: > > > > > [email protected]<mailto:flexcoders%40yahoogroups.com><mailto:flexcoders%40yahoogroups.com> > > > > > Subject: [flexcoders] Still struggling with creation complete > > > > > > > > > > > > > > > > > > > > I have a viewstack that animates its children by sliding them in and > > > > > out. It works fine when the creationPolicy is set to all, but when > > > > > it's set to auto, uncreated views slide in blank, then render > > > > > themselves. > > > > > > > > > > I thought that I could fix this by checking to see if a view has been > > > > > created yet (the only way I could figure out how to do this is > > > > > mx_internal::numChildrenCreated), and then trigger its creation with > > > > > createComponentFromDescriptor. For some reason this isn't working > > > > > though- my creationComplete function is never called...what am I > > > > > doing wrong? > > > > > > > > > > override public function set selectedIndex(value:int):void > > > > > { > > > > > _lastIndex = selectedIndex; > > > > > > > > > > if(value != _lastIndex && value >= 0 && _lastIndex >= 0) > > > > > { > > > > > _newIndex = value; > > > > > var targetChild:Container = getChildAt(value) as Container; > > > > > if (targetChild.mx_internal::numChildrenCreated < 0) > > > > > { > > > > > targetChild.addEventListener(FlexEvent.CREATION_COMPLETE,child_creation,false,0,true); > > > > > createComponentFromDescriptor(targetChild.descriptor,true); > > > > > targetChild.validateNow(); > > > > > return; > > > > > } > > > > > else > > > > > { > > > > > slideTabs(_lastIndex,_newIndex); > > > > > } > > > > > } > > > > > } > > > > > > > > > > private function child_creation(event:Event):void > > > > > { > > > > > slideTabs(_lastIndex,_newIndex); > > > > > } > > > > > > > > > > > > > > >

