We help IT Professionals succeed at work.

Viewsatck Children

SreeramojuPradeep
on
Medium Priority
444 Views
Last Modified: 2012-05-11
Hi,

I have button in my application, on click of the button i addChild i.e canvas has the child of TabNavigator...
 I would like to add the child only once...
So on the second click of the button i would like to check whether the canvas is already the child of tab navigator if yes i will not be creating new tab ..if no i will create new tab....
Below is the code snippet
 
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
					   xmlns:s="library://ns.adobe.com/flex/spark" 
					   xmlns:mx="library://ns.adobe.com/flex/mx">

	<fx:Script>
		<![CDATA[
			import mx.containers.Canvas;
			import mx.controls.TextInput;
			private var canvas1:Canvas;
			protected function addCanvas_clickHandler(event:MouseEvent):void
			{
				canvas1 = new Canvas();
				canvas1.label = "Search Results";
				var enterText:TextInput = new TextInput();
				canvas1.addChild(enterText);
				myVS.addChild(canvas1);
			}
		]]>
	</fx:Script>
	
	<s:VGroup>
		<s:Button id="addCanvas" click="addCanvas_clickHandler(event)"/>
		<mx:TabNavigator id="myVS">
			
		</mx:TabNavigator>
	</s:VGroup>
	
</s:WindowedApplication>

Open in new window

Comment
Watch Question

One way would be to disable the Button as soon as the canvas was allready created.
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                           xmlns:s="library://ns.adobe.com/flex/spark" 
                                           xmlns:mx="library://ns.adobe.com/flex/mx">

        <fx:Script>
                <![CDATA[
                        import mx.containers.Canvas;
                        import mx.controls.TextInput;
                        private var canvas1:Canvas;
                        protected function addCanvas_clickHandler(event:MouseEvent):void
                        {
                                canvas1 = new Canvas();
                                canvas1.label = "Search Results";
                                var enterText:TextInput = new TextInput();
                                canvas1.addChild(enterText);
                                myVS.addChild(canvas1);
                        }
                ]]>
        </fx:Script>
        
        <s:VGroup>
                <s:Button id="addCanvas" click="addCanvas_clickHandler(event)" enabled="{!canvas1}"/>
                <mx:TabNavigator id="myVS">
                        
                </mx:TabNavigator>
        </s:VGroup>
        
</s:WindowedApplication>

Open in new window


Another would be a if-clause in the event-handler:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                           xmlns:s="library://ns.adobe.com/flex/spark" 
                                           xmlns:mx="library://ns.adobe.com/flex/mx">

        <fx:Script>
                <![CDATA[
                        import mx.containers.Canvas;
                        import mx.controls.TextInput;
                        private var canvas1:Canvas;
                        protected function addCanvas_clickHandler(event:MouseEvent):void
                        {
                                if(!canvas1) {
                                    canvas1 = new Canvas();
                                    canvas1.label = "Search Results";
                                    var enterText:TextInput = new TextInput();
                                    canvas1.addChild(enterText);
                                    myVS.addChild(canvas1);
                                }
                        }
                ]]>
        </fx:Script>
        
        <s:VGroup>
                <s:Button id="addCanvas" click="addCanvas_clickHandler(event)"/>
                <mx:TabNavigator id="myVS">
                        
                </mx:TabNavigator>
        </s:VGroup>
        
</s:WindowedApplication>

Open in new window


But as you are using Flex4 I would suggest to use a spark NavigatorContent instead of a canvas ... this way you stay in the Flex4 world.

Author

Commented:
Ur second solution works properly...

As i know their is a problem in using Navigation content i suppose...
Pls let me know more abt it...
And pls let me know abt history management enabled property in Tab Navigator, Accordian, ViewStack.....

Well I use the NavigatorContent all the time. Haven't had any problems with it. The only problems I once had, was when using the FlexLib SuperTabNavigator ... I solved this by creating a custom version that works nicely with NavigatorContents :-)

I'd suggest to just give it a try ... I doubt you will be having Problems
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks for the support

Author

Commented:
Can u pls let me know abt history management enabled property in Tab Navigator, Accordian, ViewStack.....
In air application also when moving...
b/w the child components with in viewstack the state management happens..i.e the user previous action remains as it is...Can u let e know more abt it....
<ViewStack>
       <Canvas>
       </Canvas>
        <Canvas>
       </Canvas>
        <Canvas>
       </Canvas>
</ViewStack>
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.