how to call mxml application from action script - actionscript-3

I've one main.mxml which has login button which looks like below -
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
backgroundColor="#C4D4EF" layout="absolute">
<mx:HTTPService id="serverCall" method="POST"
url="http://localhost:8080/LDAPService/reg"
result="on_Result(event)" fault="on_Fault(event)"
/>
<mx:Script>
<![CDATA[
private function on_Result(event:ResultEvent):void {
// How to write here
}
]]>
</mx:Script>
<mx:Panel x="414" y="145" width="355" height="200" layout="absolute"
<mx:Button x="142" y="115" label="Login" id="callToServer"
click="send_data(event)"/>
</mx:Panel>
</mx:Application>
Now I want to call second.mxml file which looks like below -
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns="*" creationComplete="iFrame.visible=true"
viewSourceURL="srcview/index.html">
<mx:HBox width="100%" height="100%">
<mx:Panel title="/ Company Home" width="200" height="100%" >
</mx:Panel>
<mx:Panel width="100%" height="100%" title="Ticket Details" paddingTop="1" >
<IFrame id="iFrame" source="some service call url" width="100%" height="100%" />
<mx:ControlBar>
<mx:CheckBox id="cbVisible" label="IFrame Visible" selected="true"
click="iFrame.visible=cbVisible.selected"/>
</mx:ControlBar>
</mx:Panel>
</mx:HBox>
</mx:Application>
How can I call second.mxml from main.mxml? Please advice, Thanks for your help!

OK this example is in flex 4! it uses spark instead of mx
This shows the basics of states.
You can read more here: http://www.artima.com/articles/flex_4_states.html
This article shows the difference between flex3 and flex4 states
This is only a start. Hope this helps you.
<?xml version="1.0"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" >
<fx:Script ><![CDATA[
import mx.rpc.events.ResultEvent;
<![CDATA[
private function on_Result( event:ResultEvent ):void
{
currentState = "result";
}
]]>
]]>
</fx:Script >
<fx:Declarations >
<s:HTTPService id="serverCall"
url="http://localhost:8080/LDAPService/reg"
useProxy="false"
method="POST"
result="on_Result(event)" >
</s:HTTPService >
</fx:Declarations >
<s:states >
<s:State name="init" />
<s:State name="result" />
</s:states >
<s:Panel x="414"
y="145"
width="355"
height="200" >
<s:Button x="142"
y="115"
label="Login"
id="callToServer"
includeIn="init"
click="serverCall.send()" />
</s:Panel >
<s:Panel title="/ Company Home"
width="200"
height="100%"
includeIn="result" >
</s:Panel >
<s:Panel width="100%"
height="100%"
includeIn="result"
title="Ticket Details" >
.... your stuff
</s:Panel >
</s:Application >

Related

Flex: Spark image resize does not work

When I use resize component on image, it just disappears. Even if I give widthTo and heightTo values more than image size.
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"
xmlns:net="flash.net.*">
<fx:Script>
<![CDATA[
import mx.effects.Resize;
import mx.utils.ObjectUtil;
private function btn_click(evt:MouseEvent):void {
var arr:Array = [];
arr.push(new FileFilter("Images", ".gif;*.jpeg;*.jpg;*.png"));
fileReference.browse(arr);
}
private function fileReference_select(evt:Event):void {
fileReference.load();
}
private function fileReference_complete(evt:Event):void {
img.source = fileReference.data;
}
]]>
</fx:Script>
<fx:Declarations>
<net:FileReference id="fileReference"
select="fileReference_select(event);"
complete="fileReference_complete(event);" />
<s:Resize id="resizeBig"
target="{img}"
widthFrom="{img.width}" widthTo="{newWidth.text as Number}"
heightFrom="{img.height}" heightTo="{newHeight.text as Number}"/>
<s:Resize id="myResizeEffect"
target="{img}"
widthBy="10" heightBy="10"/>
</fx:Declarations>
<s:Image id="img"
verticalCenter="0"
horizontalCenter="0"
maxWidth="200"
maxHeight="200"
/>
<mx:ControlBar>
<mx:Button id="btn"
label="Upload"
click="btn_click(event);" />
<s:HGroup verticalAlign="middle">
<s:Label>Width:</s:Label>
<!-- <s:NumericStepper id="newWidth" minimum="1" maximum="100" value="10" /> -->
<s:TextInput id="newWidth" restrict="0-9.\\-" />
</s:HGroup>
<s:HGroup verticalAlign="middle">
<s:Label>Height:</s:Label>
<s:TextInput id="newHeight" restrict="0-9.\\-"/>
</s:HGroup>
<s:HGroup verticalAlign="middle">
<s:Button id="resize"
label="Resize"
click="resizeBig.end();resizeBig.play();"
/>
<s:Button label="Resize Me"
click="myResizeEffect.end();myResizeEffect.play();"/>
</s:HGroup>
</mx:ControlBar>
</s:WindowedApplication>
I think the binding expression doesn't like the "as Number" thing. I would try with a function that does the conversion:
widthTo="{getNumber(newWidth.text)}"

how can I call mxml application from actionscript [duplicate]

This question already has an answer here:
how to call mxml application from action script
(1 answer)
Closed 9 years ago.
I've main.mxml which has login button. It looks like below -
<mx:Script>
<![CDATA[
private function onSuccessfulLogin(event):void {
// How to call second mxml application*/
}
]]>
</mx:Script>
<mx:Panel x="414" y="145" width="355" height="200" layout="absolute"
title="Enter Your Login Information">
<mx:TextInput id="textInputName" x="147" y="12"/>
<mx:TextInput id="textInputPassword" x="147" y="57"/>
<mx:Button x="142" y="115" label="Login" id="callToServer"
<mx:Label x="37" y="14" text="User Name"/>
<mx:Label x="41" y="59" text="Password"/>
</mx:Panel>
Now on successful login I want to call another mxml application, for example second.mxml. It looks like -
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns="*" creationComplete="iFrame.visible=true"
viewSourceURL="srcview/index.html">
<mx:HBox width="100%" height="100%">
<mx:Panel title="/ Company Home" width="200" height="100%" >
<mx:Tree id="tree" width="100%" height="100%" dataProvider="{treeData}"
labelField="#label" showRoot="false"
change="iFrame.source =
(Tree(event.target).selectedItem.attribute('path').toString());" />
</mx:Panel>
<mx:Panel width="100%" height="100%" title="Ticket Details" >
<IFrame id="iFrame" source="some url" width="100%" height="100%" />
</mx:Panel>
</mx:HBox>
</mx:Application>
Please let me know how will I do it. Thanks for your help!
One simple way to let 2 Applications communicate would be LocalConnectionDocumentation here

How to access the swfcontrols from one mxml to other mxml

Hai i have SwfControl in page1.mxml,i need to hide and show that control...In page1 i hide that control and page 2 i need to show that control how to do?
Note page1.mxml is main page
page1.mxml
<?xml version="1.0" encoding="utf-8"?>
<local:WindowsControl xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
xmlns:local="*"
height="100%" width="100%"
backgroundColor="#FFFFFF"
backgroundAlpha="0">
<mx:HBox x="11" y="167" horizontalGap="0">
</mx:HBox>
<mx:SWFLoader id="loader" source="loading.swf" visible="false"/>
</local:WindowsControl>
i need to hide the SWFloader in page1.mxml and show the SWFloader in page2.mxml
page2
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" creationComplete="init()" width="164" height="150" cornerRadius="3">
<mx:Script>
<![CDATA[
import flash.media.Microphone;
import flash.media.Video;
public function init():void
{
loader.visible=true;
}
]]>
</mx:Script>
<mx:VBox height="100%" width="100%" horizontalAlign="center" backgroundColor="#000000" >
<VideoContainer id="vids" opaqueBackground="true" width="160" height="120" />
</mx:VBox>
</mx:Canvas>
The right way to do this is by dispatching events to parent container of page1 and page2.
The parent container will relay the message/action to the target page. Your event will contain info of what is supposed to happen.

Flex popup issue with keyboard key like C,V,X,A key

As i report earlier in the issues of pop-up of that i'm not able to write "a,c, v and x" characters in the text-input field in pop-up.
Shortcut actions(a = select all, c= copy, v = paste and x = cut) are performed on those keys on keys text-input fields.
Complete case:
In the popup there is a data-grid and in the data-grid an item renderer where i enter the input.
Here is code
<CheckBoxGrid:CheckBoxDataGrid id="id_DataGrid"
width="95%" height="90%" allowMultipleSelection="true" editable="true"
dataProvider="{inHouseLabList}"
draggableColumns="false"
useRollOver="false"
styleName="gridStyle"
rowCount="{id_DataGrid.dataProvider.length + 1}"
variableRowHeight="true" columnWidths="{[20,'10%','25%', '25%','30%']}">
<CheckBoxGrid:columns>
<mx:DataGridColumn dataField=""
headerText=""
rendererIsEditor="true"
sortable="false"
itemRenderer="com.zigron.controls.extended.components.CheckBoxGrid.CheckBoxRenderer"
headerRenderer="com.zigron.controls.extended.components.CheckBoxGrid.CheckBoxHeaderRenderer"
editorDataField="selected"
/>
<mx:DataGridColumn headerText="Test Code" dataField="InHouseLabTestTypeDTO.TestCode" editable="false" sortable="false"/>
<mx:DataGridColumn headerText="Test Name" dataField="InHouseLabTestTypeDTO.TestName" editable="false" />
<mx:DataGridColumn headerText="Result" dataField="TestResult" editable="true" />
<mx:DataGridColumn headerText="Normal Range" dataField="InHouseLabTestTypeDTO.TestRange" editable="false" />
</CheckBoxGrid:columns>
</CheckBoxGrid:CheckBoxDataGrid>
It works without issues in FF11, DataGrid in a popup with a TextInput in an itemRenderer, A,C,V,X or CTRL+A,C,V,X works:
Application.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
minWidth="955" minHeight="600" layout="vertical">
<mx:Script>
<![CDATA[
import mx.managers.PopUpManager;
protected function clickHandler(event:MouseEvent):void
{
var popup:MyPopup = new MyPopup();
PopUpManager.addPopUp(popup, this)
}
]]>
</mx:Script>
<mx:Button label="click me!" click="clickHandler(event)" />
</mx:Application>
MyPopup.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="400" height="300">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var ac:ArrayCollection = new ArrayCollection([{}]);
]]>
</mx:Script>
<mx:DataGrid width="100%" height="100%" dataProvider="{ac}">
<mx:columns>
<mx:DataGridColumn headerText="MyTextInput">
<mx:itemRenderer>
<mx:Component>
<mx:TextInput />
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:Panel>
Please try it and report.
Hope that helps

How to come back in main application on click of logout button which is in application's component in flex4?

Please check the code and tell me How I will be back in Login Page after click of logout which is in application's component.
Project.mxml
<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" width="100%" height="100%" creationComplete="init()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<mx:StringValidator source="{uname}" id="unameValid" property="text"/>
<mx:StringValidator source="{password}" id="passwordValid" property="text"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.ValidationResultEvent;
import mx.validators.Validator;
private var myValidators:Array = new Array;
private var nav:Navigation;
private function init():void{
btnLogin.addEventListener(MouseEvent.CLICK,validateForm);
myValidators = [unameValid,passwordValid];
}
private function validateForm(event:Event):void{
//Alert.show("in validate form");
var errors:Array = Validator.validateAll(myValidators);
if(errors.length == 0){
loginUser();
}else{
Alert.show("in else");
}
}
private function loginUser():void{
//Alert.show("In login Form");
nav = new Navigation();
this.addElement(nav);
}
]]>
</fx:Script>
<s:Label text="Login Form" fontWeight="bold" fontSize="16" horizontalCenter="-110"
verticalAlign="middle" verticalCenter="-280"/>
<mx:Form horizontalCenter="-120" verticalCenter="-200" fontWeight="bold" verticalGap="20">
<mx:FormItem label="UserName">
<s:TextInput id="uname" restrict="A-Z a-z" focusIn="uname.errorString = null" text="Priyanka"/>
</mx:FormItem>
<mx:FormItem label="Password">
<s:TextInput id="password" displayAsPassword="true" focusIn="password.errorString = null" text="aamir#23"/>
</mx:FormItem>
<mx:FormItem>
<mx:HBox horizontalGap="20">
<s:Button label="Login" id="btnLogin" />
<mx:LinkButton label="Register" id="register"/>
</mx:HBox>
</mx:FormItem>
</mx:Form>
</s:Application>
Navigation.mxml
<mx:Panel xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" width="100%" height="100%" xmlns:local="*">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import spark.components.Application;
private function logout(event:MouseEvent):void{
}
]]>
</fx:Script>
<s:TabBar id="tabs" left="10" y="5" dataProvider="{vs}"/>
<mx:ViewStack id="vs" width="90%" height="90%" left="10" y="30">
<s:NavigatorContent label="DashBoard" width="100%" height="100%">
<s:BorderContainer width="100%" height="100%" borderWeight="2" cornerRadius="3" dropShadowVisible="true">
<s:Label text="in DashBoard"/>
</s:BorderContainer>
</s:NavigatorContent>
<s:NavigatorContent label="User Information" width="100%" height="100%">
<s:BorderContainer width="100%" height="100%" borderWeight="2" cornerRadius="3" dropShadowVisible="true">
<s:Label text="in UserInfo"/>
</s:BorderContainer>
</s:NavigatorContent>
</mx:ViewStack>
<s:Button x="494" y="1" label="Logout" id="btnLogout" click="logout(event);"/>
</mx:Panel>
You should create a custom event:
package
{
import flash.events.Event;
public class LogoutEvent extends Event
{
public static const LOG_OUT:String = "logOut";
public function LogoutEvent(type:String)
{
super(type,false,false);
}
public override function clone():Event
{
return new LogoutEvent(type);
}
public override function toString():String
{
return formatToString("LogoutEvent");
}
}
}
Now you should dispatch this event:
<mx:Panel xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" layout="absolute" width="100%" height="100%" xmlns:local="*">
<fx:Metadata>
[Event(name="logOut", type="LogoutEvent")]
</fx:Metadata>
<fx:Script>
<![CDATA[
import spark.components.Application;
private function logout(event:MouseEvent):void{
dispatchEvent(new LogoutEvent(LogoutEvent.LOG_OUT));
}
]]>
</fx:Script>
<s:TabBar id="tabs" left="10" y="5" dataProvider="{vs}"/>
<mx:ViewStack id="vs" width="90%" height="90%" left="10" y="30">
<s:NavigatorContent label="DashBoard" width="100%" height="100%">
<s:BorderContainer width="100%" height="100%" borderWeight="2" cornerRadius="3" dropShadowVisible="true">
<s:Label text="in DashBoard"/>
</s:BorderContainer>
</s:NavigatorContent>
<s:NavigatorContent label="User Information" width="100%" height="100%">
<s:BorderContainer width="100%" height="100%" borderWeight="2" cornerRadius="3" dropShadowVisible="true">
<s:Label text="in UserInfo"/>
</s:BorderContainer>
</s:NavigatorContent>
</mx:ViewStack>
<s:Button x="494" y="1" label="Logout" id="btnLogout" click="logout(event);"/>
</mx:Panel>
Finally, you should handle it and close your window:
<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" width="100%" height="100%" creationComplete="init()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<mx:StringValidator source="{uname}" id="unameValid" property="text"/>
<mx:StringValidator source="{password}" id="passwordValid" property="text"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.ValidationResultEvent;
import mx.validators.Validator;
private var myValidators:Array = new Array;
private var nav:Navigation;
private function init():void{
btnLogin.addEventListener(MouseEvent.CLICK,validateForm);
myValidators = [unameValid,passwordValid];
}
private function validateForm(event:Event):void{
//Alert.show("in validate form");
var errors:Array = Validator.validateAll(myValidators);
if(errors.length == 0){
loginUser();
}else{
Alert.show("in else");
}
}
private function loginUser():void{
//Alert.show("In login Form");
nav = new Navigation();
this.addElement(nav);
nav.addEventListener(LogoutEvent.LOG_OUT, nav_logOutHandler);
}
private function nav_logOutHandler(event:LogoutEvent):void
{
removeElement(nav);
nav.removeEventListener(LogoutEvent.LOG_OUT, nav_logOutHandler);
nav = null;
}
]]>
</fx:Script>
<s:Label text="Login Form" fontWeight="bold" fontSize="16" horizontalCenter="-110"
verticalAlign="middle" verticalCenter="-280"/>
<mx:Form horizontalCenter="-120" verticalCenter="-200" fontWeight="bold" verticalGap="20">
<mx:FormItem label="UserName">
<s:TextInput id="uname" restrict="A-Z a-z" focusIn="uname.errorString = null" text="Priyanka"/>
</mx:FormItem>
<mx:FormItem label="Password">
<s:TextInput id="password" displayAsPassword="true" focusIn="password.errorString = null" text="aamir#23"/>
</mx:FormItem>
<mx:FormItem>
<mx:HBox horizontalGap="20">
<s:Button label="Login" id="btnLogin" />
<mx:LinkButton label="Register" id="register"/>
</mx:HBox>
</mx:FormItem>
</mx:Form>
</s:Application>
The quickest way would be:
private function logout(event:MouseEvent):void{
parent.removeElement(this);
}
However, Constantiner's method is the proper way.
Also, if you are using flex 4, why not use the spark Form,FormItem,Panel and HGroup (Instead of HBox)