?
Solved

Viewsatck Children

Posted on 2011-04-19
6
Medium Priority
?
431 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

0
Comment
Question by:SreeramojuPradeep
  • 3
  • 3
6 Comments
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 35422780
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.
0
 

Author Comment

by:SreeramojuPradeep
ID: 35422957
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.....

0
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 35422974
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
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 500 total points
ID: 35422979
Oh ... and if you change my first version to this:
<?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;
                        [Bindable]
                        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

It should work too ... (notice the Bindable metadata?)
0
 

Author Closing Comment

by:SreeramojuPradeep
ID: 35423156
Thanks for the support
0
 

Author Comment

by:SreeramojuPradeep
ID: 35423190
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>
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
Most folks would know the basics of how Dropbox works, so that’s not the purpose of this article. Security is what it’s all about, so here I’ll share how I choose to secure my Dropbox Account and the Data it contains.
Integration Management Part 2
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month17 days, 5 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question