Flex summary 2

Source: Internet
Author: User

1. Two modules (transmission between modules)
Master Program :
<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml">
<Mx: moduleloader url = "m1.swf" id = "M1"/>
<Mx: moduleloader url = "m2.swf" id = "m2"/>
</MX: Application>
Module 1:
<Mx: SCRIPT>
<! [CDATA [
Public Function getdata (): String {
Return "module data ";
}
]>
</MX: SCRIPT>
Module 2:
<Mx: SCRIPT>
<! [CDATA [
[Bindable]
Private var title: string;
Private function changedata (): void {
Title = parentapplication. m1.child. getdata ();
}
]>
</MX: SCRIPT>
<Mx: hbox>
<Mx: Label id = "L1" text = "title:"/>
<Mx: Label id = "mytitle" text = "{Title}"/>
</MX: hbox>
<Mx: button id = "B1" label = "Data Transmission" Click = "changedata ()"/>

2 Flex + struts1 + livecycle integration summary
let's take a look at how to connect to Java in the form of httpservice alone.
1) create a flex-Project project.
2) download a flex project. war stuff (it seems that the latest version of livecycle does not have this stuff, and you need to download it again)
3) when creating a flex-project, select the J2EE container, if you do not select "Use Remote Object Access Service"
4) after setting the Tomcat container, pay attention to flex. the WEB-INF \ flex directory under war is copied to the WEB-INF of the current project, copy all the packages under Web-INF \ Lib to the Lib under Web-INF of the current project.
5) modify web. XML to support structs1 and access in the form of a http://xxxx.mxml, or Tomcat will not parse the form of mxml.

<Web-app id = "webapp_id" version = "2.4" xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<Display-Name>
Userinfosys </display-Name>
<Context-param>
<Param-Name> Flex. Class. Path </param-Name>
<Param-value>/WEB-INF/flex/hotfixes,/WEB-INF/flex/jars </param-value>
</Context-param>

<! -- HTTP flex session attribute and binding listener support -->
<Listener>
<Listener-class> Flex. messaging. httpflexsession </listener-class>
</Listener>

<! -- Messagebroker servlet -->
<Servlet>
<Servlet-Name> messagebrokerservlet </servlet-Name>

<Servlet-class> Flex. messaging. messagebrokerservlet </servlet-class>
<Init-param>
<Param-Name> services. configuration. File </param-Name>
<Param-value>/WEB-INF/flex/services-config.xml </param-value>
</Init-param>
<Init-param>
<Param-Name> Flex. Write. Path </param-Name>
<Param-value>/WEB-INF/flex</param-value>
</Init-param>
<Load-on-startup> 1 </load-on-startup>
</Servlet>

<Servlet>
<Servlet-Name> flexmxmlservlet </servlet-Name>


<Servlet-class> Flex. Bootstrap. bootstrapservlet </servlet-class>
<Init-param>
<Param-Name> servlet. Class </param-Name>
<Param-value> Flex. webtier. server. J2EE. mxmlservlet </param-value>
</Init-param>
<Init-param>
<Param-Name> webtier. configuration. File </param-Name>
<Param-value>/WEB-INF/flex/flex-webtier-config.xml </param-value>
</Init-param>
<Load-on-startup> 1 </load-on-startup>
</Servlet>


flexswfservlet
flex. bootstrap. bootstrapservlet

servlet. class
flex. webtier. server. j2EE. swfservlet


2

<Servlet>
<Servlet-Name> flexforbiddenservlet </servlet-Name>

<Servlet-class> Flex. Bootstrap. bootstrapservlet </servlet-class>
<Init-param>
<Param-Name> servlet. Class </param-Name>
<Param-value> Flex. webtier. server. J2EE. forbiddenservlet </param-value>
</Init-param>
</Servlet>

<Servlet>
<Servlet-Name> flexinternalservlet </servlet-Name>
<Servlet-class> Flex. Bootstrap. bootstrapservlet </servlet-class>
<Init-param>
<Param-Name> servlet. Class </param-Name>
<Param-value> Flex. webtier. server. J2EE. filemanager. filemanagerservlet </param-value>
</Init-param>
<Load-on-startup> 10 </load-on-startup>
</Servlet>

<! -- Standard action servlet configuration -->
<Servlet>
<Servlet-Name> action </servlet-Name>
<Servlet-class> org. Apache. Struts. Action. actionservlet </servlet-class>
<Init-param>
<Param-Name> config </param-Name>
<Param-value>/WEB-INF/struts-config.xml </param-value>
</Init-param>
<Load-on-startup> 2 </load-on-startup>
</Servlet>

<Servlet-mapping>
<Servlet-Name> messagebrokerservlet </servlet-Name>
<URL-pattern>/messagebroker/* </url-pattern>
</Servlet-mapping>

<Servlet-mapping>
<Servlet-Name> flexmxmlservlet </servlet-Name>
<URL-pattern> *. mxml </url-pattern>
</Servlet-mapping>

<Servlet-mapping>
<Servlet-Name> flexswfservlet </servlet-Name>
<URL-pattern> *. SWF </url-pattern>
</Servlet-mapping>

<Servlet-mapping>
<Servlet-Name> flexforbiddenservlet </servlet-Name>
<URL-pattern> *. As </url-pattern>
</Servlet-mapping>

<Servlet-mapping>
<Servlet-Name> flexforbiddenservlet </servlet-Name>
<URL-pattern> *. SWC </url-pattern>
</Servlet-mapping>

<Servlet-mapping>
<Servlet-Name> flexinternalservlet </servlet-Name>
<URL-pattern>/flex-Internal/* </url-pattern>
</Servlet-mapping>

<! -- Standard action Servlet Mapping -->
<Servlet-mapping>
<Servlet-Name> action </servlet-Name>
<URL-pattern> *. DO </url-pattern>
</Servlet-mapping>
After 6, you can perform struts1 In the src directory as in the original struts1.
7. Use the httpservice component on the flex Interface
<Mx: httpservice id = "listsrv" url = "/userinfosys/listallusers. Do"/>
<Mx: panel title = "current system user" width = "100%" Height = "100%">
<Mx: tilelist id = "list" dataprovider = "{listsrv. lastresult. User }"
Itemrenderer = "BREF" width = "100%" Height = "100%"/>
</MX: Panel>

<Mx: SCRIPT>
<! [CDATA [
Import MX. Controls. Alert;
Import MX. rpc. Events. faultevent;
Import MX. rpc. Events. resultevent;

Private function resulthandler (Event: resultevent): void
{
Alert. Show ("Update successful! ");
}

Private function faulthandler (Event: faultevent): void
{
Alert. Show (event. fault. message, "update cannot be completed! ");
}

]>
</MX: SCRIPT>

<Mx: httpservice id = "updatesrv" method = "get" url = "/userinfosys/updateuser. Do" result = "resulthandler (event )"
Fault = "faulthandler (event)">
<Mx: Request>
<User_id> {list. selecteditem. user_id} </user_id>
<Name> {username. Text} </Name>
<Title> {titl. Text} </title>
<Image >{list. selecteditem. Image} </image>
<Imagebref> {list. selecteditem. imagebref} </imagebref>
<Description> {description. Text} </description>
</MX: Request>
</MX: httpservice>
Note: {listsrv. lastresult. User} is actually a list returned by struts1 to the interface. Pay attention to the use of lastresult;

<Mx: httpservice id = "updatesrv"> indicates that when updating data information, the current information must be sent to the sevice layer of struts1 for processing.

 

8. Use livecycle In Flex
1) Remember to use the use Remote Object Access Service in flex-project.
2) modify the remoting-config.xml under the web-INF \ flex directory as follows:
<Destination ID = "user">
<Properties>
<Source> Flex. userinfosys. DB. User. userservice </source>
</Properties>
</Destination>
This indicates that the service layer in struts1 needs to be remotely called through flex.

3) use the remoteobject component
<Mx: remoteobject id = "SRV" Destination = "user"/>
<Mx: panel title = "all system users" width = "70%" Height = "100%">
<Mx: DataGrid width = "100%" id = "list" dataprovider = "{srv. getusers. lastresult}" Height = "100%">
<Mx: columns>
<Mx: datagridcolumn headertext = "name" datafield = "name"/>
<Mx: datagridcolumn headertext = "job" datafield = "title"/>
<Mx: datagridcolumn headertext = "" datafield = "Description"/>
</MX: columns>
</MX: DataGrid>
4) if our application is divided into two parts, the data list is displayed on the left, and the data on the left is shown on the right, and the data on the left is shown on the right.
For details, you can do this:
A first creates a user.,
[Managed]
[Remoteclass (alias = "flex. userinfosys. DB. User. USERPROFILE")]

Public class user
{
Public Function user ()
{
}
Public var userid: int;
Public var name: string;
Public var title: string;
Public var image: string;
Public var imagebref: string;
Public var Description: string;

}
Remoteclass establishes a user ing between the user class (ActionScript) and the pojo class of Java, and converts the ActionScript class to the pojo class of Java.

Note that the default empty constructor must be used in the pojo class of Java. Otherwise, errors may occur.
B. Create an MX control.
<Mx: Panel xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute" width = "367" Height = "522" Title = "details" xmlns: Local = "*">

<Local: User ID = "user"
Userid = "{user. userid }"
Name = "{username. Text }"
Title = "{titl. Text }"
Image = "{image. Text }"
Imagebref = "{imagebref. Text }"
Description = "{description. Text}"/>


Import MX. controls. alert;
Import MX. RPC. events. faultevent;
Import MX. RPC. events. resultevent;

private function resulthandler (Event: resultevent): void
{< br> alert. Show ("updated successfully! ");
}< br>
private function faulthandler (Event: faultevent): void
{< br> alert. show (event. fault. message, "update cannot be completed! ");
}

]>
</MX: SCRIPT>
<Mx: remoteobject id = "SRV" Destination = "user" result = "resulthandler (event)" fault = "faulthandler (event)"/>
<Mx: Image Top = "10" Left = "28" horizontalalign = "center" Source = "images/{user. image} "width =" 140 "Height =" 210 "/>
<Mx: Form width = "100%" Top = "220" Left = "10" Height = "185">
<Mx: formitem label = "name">
<Mx: textinput text = "{user. name}" id = "username"/>
</MX: formitem>
<Mx: formitem label = "position">
<Mx: textinput text = "{user. Title}" id = "titl"/>
</MX: formitem>
.......
<Mx: button label = "Update" Click = "srv. Update (User);"/>

5. Note that when creating a flex project, it is best to set content folder to webroot, so that you can use myeclipse's add WEB Project
Capbilities, which converts a project to a J2EE project and can be deployed to Tomcat (do not select to regenerate the web. XML. Otherwise, the original flex web. XML will be overwritten)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.