Whats mistake in my code [closed] - actionscript-3

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Iam tyring to reproduce the same output as this: http://tourdeflex.adobe.com/flex4samples/GroupsAndContainers/TabbedNavigator/sample1.html
Below is my own code developed myself, but iam not getting required output.. dont know what went wrong. pls kindly run my code and provide me correct solution:
TabBarDemo.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:components="components.*">
<fx:Script>
<![CDATA[
import events.EmployeeEvent;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import vo.EmployeeVO;
public var empVO: EmployeeVO;
[Bindable]
public var empList: ArrayCollection;
protected function contactInfo_employeeEventHandler(event:EmployeeEvent):void
{
empVO = event.employeeInfoVO;
if(empVO != null)
empList.addItem(empVO);
else
Alert.show("Object is null");
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:VGroup>
<s:TabBar dataProvider="{contact}" />
<mx:ViewStack id="contact"
resizeToContent="true">
<components:ContactInfo id="contactInfo"
label="Employee Info"
employeeEvent="contactInfo_employeeEventHandler(event)"/>
<components:ContactList label="Employee List"
empList="{empList}"/>
</mx:ViewStack>
</s:VGroup>
</s:Application>
ContactInfo.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:NavigatorContent xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">
<fx:Metadata>
[Event(name="employeeEvent", type="events.EmployeeEvent")]
</fx:Metadata>
<fx:Script>
<![CDATA[
import events.EmployeeEvent;
import vo.EmployeeVO;
protected function submit_clickHandler(event:MouseEvent):void
{
var empVO: EmployeeVO = new EmployeeVO();
empVO.empName = empName.text;
empVO.address = address.text;
empVO.state = state.text;
empVO.city = city.text;
empVO.zip = zip.text;
var empEvent: EmployeeEvent = new EmployeeEvent("employeeEvent", empVO);
dispatchEvent(empEvent);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Form>
<s:FormItem label="Name">
<s:TextInput id="empName"/>
</s:FormItem>
<s:FormItem label="Address">
<s:TextInput id="address" />
</s:FormItem>
<s:FormItem label="City">
<s:TextInput id="city" />
</s:FormItem>
<s:FormItem label="State">
<s:TextInput id="state" />
</s:FormItem>
<s:FormItem label="Zip">
<s:TextInput id="zip" />
</s:FormItem>
<s:FormItem>
<s:Button id="submit"
label="Submit"
click="submit_clickHandler(event)"/>
</s:FormItem>
</s:Form>
</s:NavigatorContent>
ContactList.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:NavigatorContent xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300"
>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import spark.components.List;
import vo.EmployeeVO;
[Bindable]
public var empList: ArrayCollection;
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:DataGrid dataProvider="{empList}"/>
</s:NavigatorContent>
EmployeeEvent.as
package events
{
import flash.events.Event;
import vo.EmployeeVO;
public class EmployeeEvent extends Event
{
public var employeeInfoVO: EmployeeVO;
public function EmployeeEvent(type: String, employeeInfoVO: EmployeeVO)
{
super(type);
this.employeeInfoVO = employeeInfoVO;
}
}
}
EmployeeVO.as
package vo
{
public class EmployeeVO
{
public function EmployeeVO()
{
}
public var empName: String;
public var address: String;
public var state: String;
public var city: String;
public var zip: String;
}
}
Awaiting your responses!

The problem is that you haven't initialized empList:ArrayCollection. Just use
[Bindable]
public var empList: ArrayCollection = new ArrayCollection();
(I'm assuming that the required output you aren't getting is that the contact list should show list of employee info submitted in contact info)

If you right click on the link tht you have posted, you can view source.
Here

Related

flex4 moduls data passing from one module to another module

I have a Flex 4 application that loads a two module. first module is user login module and second one is user balance. when user application start login screen is displayed. when user login this module pass to java and process some validations and return to the flex. in flex if user is valid pass that user name to the second module. in that module using that name again pass user name to java and get balance of that user.
but my code is not working?
am tring this code:-
modules.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:views="views.*">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<views:module2/>
<views:module1>
</views:module1>
</s:Application>
module1.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Module xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
protected function login_resultHandler(event:ResultEvent):void
{
if(har.text=="valid"){
var username:String = "module2.swf?" + "username=" +user.text;
bordercontainerlogin.visible=false;
}else if(har.text=="not-valid")
{
validation.text="! make sure user name & password correct";
}
else
validation.text=har.text
}
protected function user_focusInHandler(event:FocusEvent):void
{
if((user.text=="User name")||(user.text==""))
{
user.text="";
}
}
protected function user_focusOutHandler(event:FocusEvent):void
{
if((user.text=="User name")||(user.text==""))
{
user.text="User name";
}
}
protected function pass_focusInHandler(event:FocusEvent):void
{
pass.displayAsPassword=true;
if((pass.text=="Password")||(pass.text==""))
{
pass.text="";
}
}
protected function pass_focusOutHandler(event:FocusEvent):void
{
if((pass.text=="Password")||(pass.text==""))
{
pass.displayAsPassword=false;
pass.text="Password";
}
}
protected function button1_clickHandler(event:MouseEvent):void
{
if(((user.text=="User name")||(user.text=="")) || ((pass.text=="Password")||(pass.text=="")))
{
if((user.text=="User name")||(user.text==""))
{
//validation.text="! Make sure user name shouidn't be empty";
Alert.show(user.text); }
else if((pass.text=="Password")||(pass.text==""))
{
validation.text="! Make sure Password shouidn't be empty";
}
}
else
{
login.cancel();
login.send();
}
}
protected function button1_mouseOutHandler(event:MouseEvent):void
{
Mouse.cursor=MouseCursor.ARROW;
}
protected function button1_mouseOverHandler(event:MouseEvent):void
{
Mouse.cursor=MouseCursor.BUTTON;
}
]]>
</fx:Script>
<fx:Declarations>
<s:HTTPService id="login" url="http://192.168.1.4:8400/myapp/login" method="POST" result="login_resultHandler(event)">
<s:request xmlns="">
<myname>{user.text}</myname>
<passwd>{pass.text}</passwd>
</s:request>
</s:HTTPService>
</fx:Declarations>
<s:BorderContainer x="0" y="-1" width="100%" height="100%" id="bordercontainerlogin" backgroundColor="#fa0000" backgroundAlpha=".2">
<s:ModuleLoader id="modulerload"/>
<s:Panel width="257" height="205" fontWeight="bold" horizontalCenter="-44" verticalCenter="-56" id="loginpanel" visible="true" title="User Login">
<s:TextInput id="user" y="61" horizontalCenter="-3" text="User name" focusIn="user_focusInHandler(event)" focusOut="user_focusOutHandler(event)"/>
<s:TextInput id="pass" y="99" focusIn="pass_focusInHandler(event)"
focusOut="pass_focusOutHandler(event)" horizontalCenter="-3" text="Password"/>
<s:Button y="137" label="LOGIN" click="button1_clickHandler(event)" horizontalCenter="-4"
mouseOut="button1_mouseOutHandler(event)"
mouseOver="button1_mouseOverHandler(event)"/>
<s:Label id="validation" x="4" y="167" color="#D90D0D"/>
</s:Panel>
<!--<s:ComboBox id="resultData" dataProvider="{reg.lastResult.status}" visible="true" selectedIndex="0"/>-->
<s:TextInput id="har" x="43" y="149" text="{login.lastResult.status}" visible="false" />
</s:BorderContainer>
</s:Module>
module2.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Module xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300" creationComplete="module1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;
var username:String;
protected function getbalance_resultHandler(event:ResultEvent):void
{
username= this.loaderInfo.url.toString();
getbalance.cancel();
getbalance.send();
}
protected function module1_creationCompleteHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
}
]]>
</fx:Script>
<fx:Declarations>
<s:HTTPService id="getbalance" url="http://192.168.1.4:8400/myapp/getbalance" method="POST" result="getbalance_resultHandler(event)">
<s:request xmlns="">
<myname>{username}</myname>
</s:request>
</s:HTTPService>
</fx:Declarations>
<s:Label text="welcome {username}" id="welcomelabel" />
<s:TextInput text="{getbalance.lastResult.status}" id="balance"/>
</s:Module>
Because module2 is creationComplete in this time,So,you can Because module2 is creationComplete in this time,So,you can be in when login_resultHandler load module2

How to access a public function outside custom component in flex?

I have an application width a mx:ViewStack component with differents view components under each s:NavigatorContent as it follows.
<mx:ViewStack id="vsOne" resizeToContent="true">
<s:NavigatorContent label="First">
<package:MyFirstComponent id="myFirstComponent"/>
</s:NavigatorContent>
<s:NavigatorContent label="Second">
<package:MySecondComponent id="mySecondComponent"/>
</s:NavigatorContent>
</mx:ViewStack>
And this is package.MyFirstComponent's important part..
<s:Button label="Next" click="somethingToGoForward()"/>
What I've tried:
Calling somethingToGoForward() in the view component and triyng to access to a parent vsOne: Don't work.
Calling parent.somethingToGoForward() (when this method is in the same mxml as the ViewStack): Don't work
How can I change my ViewStack's selectedIndex from anywhere outside the mxml file containing it?
Thanks.
This is an example using simple events:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" initialize="application1_initializeHandler(event)"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:local="*">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function application1_initializeHandler(event:FlexEvent):void
{
viewStack.selectedChild=one;
}
protected function one_changeViewHandler(event:FlexEvent):void
{
viewStack.selectedChild=two;
}
protected function two_changeViewHandler(event:FlexEvent):void
{
viewStack.selectedChild=one;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:ViewStack id="viewStack" >
<local:ccomp id="one" changeView="one_changeViewHandler(event)" text="LAbel ONE">
</local:ccomp>
<local:ccomp id="two" changeView="two_changeViewHandler(event)" text="LAbel TWO" >
</local:ccomp>
</mx:ViewStack>
</s:Application>
ccomp is a custom component
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300">
<fx:Metadata>
[Event(name="changeView", type="mx.events.FlexEvent")]
</fx:Metadata>
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
private var _text:String;
public function get text():String
{
return _text;
}
[Bindable]
public function set text(value:String):void
{
_text = value;
}
protected function button1_clickHandler(event:MouseEvent):void
{
this.dispatchEvent(new FlexEvent("changeView",true));
}
]]>
</fx:Script>
<fx:Declarations>
</fx:Declarations>
<s:Button label="Change" click="button1_clickHandler(event)">
</s:Button>
<s:Label fontSize="24" text="{text}">
</s:Label>
</mx:HBox>
Davide

FLEX DataGrid Column Modification

I am new in Flex. I want to display data in attached grid format. I found best way to display in DataGrid. But the CIs column has multiple entries so because of that other columns will duplicate. I want to avoid duplicate data in other columns. Attached screenshot is of excel, i want to achieve same format in Flex. I am using Flex 4.5
Best way I see to do what you want is to create a custom item renderer for the CLS column and have it render as a list control. That way, the CLS item in each row will only take up one row instead of multiple rows.
You can get some idea by following code... you can build logic using below concept for your implementation. Below example is sample not complete according to your requirement: -
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.core.UIComponent;
import mx.events.AdvancedDataGridEvent;
import mx.events.ListEvent;
[Bindable]
private var dpHierarchy:ArrayCollection= new ArrayCollection
([
{name:"Barbara Jennings", address: "Arizona", contact:999970, orders:["1"]},
{name:"Dana Binn", address: "Arizona", contact:9999130, orders:["2"]},
{name:"Joe Smith", address: "California", contact:9992929, orders:["3"]},
{name:"Alice Treu", address: "California", contact:9999230, orders:["4"]}
]);
private function addOrder():void
{
for(var i:int = 0 ; i < dpHierarchy.length; i++)
{
if(dropDownID.selectedItem.name == dpHierarchy[i].name)
{
var itemUpdated:Array = dpHierarchy[i].orders;
itemUpdated.push(orderNumber.text);
dpHierarchy[i].orders = itemUpdated;
dpHierarchy.itemUpdated(dpHierarchy[i]);
break;
}
}
}
]]>
</fx:Script>
<mx:VBox x="30" y="30" width="450" height="400">
<s:HGroup>
<s:Button label="Add Order" click="addOrder()"/>
<s:DropDownList id="dropDownID" dataProvider="{dpHierarchy}" labelField="name" selectedIndex="0"/>
<s:TextInput id="orderNumber" width="100"/>
</s:HGroup>
<mx:AdvancedDataGrid id="myADG"
dataProvider="{dpHierarchy}"
variableRowHeight="true" wordWrap="true">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="name" headerText="Name"/>
<mx:AdvancedDataGridColumn dataField="address" headerText="Address"/>
<mx:AdvancedDataGridColumn dataField="contact" headerText="Contact"/>
<mx:AdvancedDataGridColumn dataField="orders" headerText="Orders" itemRenderer="OrderItemRenderer"/>
</mx:columns>
</mx:AdvancedDataGrid>
</mx:VBox>
</s:Application>
Item Reenderer Name: - OrderItemRenderer
<?xml version="1.0" encoding="utf-8"?>
<s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
focusEnabled="true" width="90%" height="90%">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var initDG:ArrayCollection = new ArrayCollection();
override public function set data(value:Object):void
{
super.data = value;
initDG = new ArrayCollection(value.orders)
}
]]>
</fx:Script>
<mx:DataGrid id="dataGrid" dataProvider="{initDG}" headerHeight="0" rowCount="{initDG.length}"/>
</s:MXAdvancedDataGridItemRenderer>

Push Data Into TabbedViewNavigator in View

I have a view like this in my Flex mobile Application:
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="aaa" actionBarVisible="false" creationComplete="view1_creationCompleteHandler(event)">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import valueObjects.Hasta;
import mx.events.FlexEvent;
public var gelen:Hasta= new Hasta();
protected function view1_creationCompleteHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
gelen=data as Hasta;
}
]]>
</fx:Script>
<s:TabbedViewNavigator width="100%" height="110%">
<s:ViewNavigator id="vn1" label="Hasta bilgileri-Hasta Yatış Bilgileri" width="100%" height="100%" firstView="views.HastabilgileriView" />
<s:ViewNavigator id="vn2" label="Menu-Doktor Bilgileri" width="100%" height="100%" firstView="views.MenuView"/>
</s:TabbedViewNavigator>
And I want to send data(gelen) to tabbedviews (to views.HastabilgileriView/views.MenuView) How can I do that?
try it in this way:
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="aaa" actionBarVisible="false" creationComplete="view1_creationCompleteHandler(event)">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import valueObjects.Hasta;
import mx.events.FlexEvent;
[Bindable]
public var gelen:Hasta= new Hasta();
protected function view1_creationCompleteHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
gelen=data as Hasta;
}
]]>
</fx:Script>
<s:TabbedViewNavigator width="100%" height="110%">
<s:ViewNavigator id="vn1" label="Hasta bilgileri-Hasta Yatış Bilgileri" width="100%" height="100%" firstView="views.HastabilgileriView" firstViewData="{gelen}" />
<s:ViewNavigator id="vn2" label="Menu-Doktor Bilgileri" width="100%" height="100%" firstView="views.MenuView" firstViewData="{gelen}"/>
</s:TabbedViewNavigator>
To push data between views you can use :
navigator.pushView(views.SomeView, data);
Check out this link and if you want additional information check out the following link. I think these links will provide you with the information required to achieve your task.

How to add items to a datagrid at runtime in flex4?

My UserInfromation form contains two input fields username,location(city) and one radio button as gender and two buttons add and reset.when I click on add button that data will be added in datagrid at runtime.
I am unable to reproduce how will i do this.
can anyone help me on this with example?
Here is a sample app (with code):
<?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">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
private var ac:ArrayCollection = new ArrayCollection();
protected function addBtn_clickHandler(event:MouseEvent):void
{
var obj:Object = new Object();
obj.userName = userNameTI.text;
obj.location = locationTI.text;
ac.addItem(obj);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:Form width="100%">
<mx:FormItem label="UserName:">
<s:TextInput id="userNameTI"/>
</mx:FormItem>
<mx:FormItem label="Location:">
<s:TextInput id="locationTI"/>
</mx:FormItem>
</mx:Form>
<s:Button id="addBtn" label="Add" click="addBtn_clickHandler(event)"/>
<mx:DataGrid id="dg" width="100%" dataProvider="{ac}"/>
</s:WindowedApplication>
Couple of things are left for you as an exercise :)