<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
  <channel>
    <title>快乐生活，快乐工作</title>
    <description></description>
    <link>http://tangshuo.javaeye.com</link>
    <language>UTF-8</language>
    <copyright>Copyright 2003-2008, JavaEye.com</copyright>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <generator>JavaEye - 做最棒的软件开发交流社区</generator>
      <item>
        <title>Struts2中实现自定义分页标签 －－功能扩充</title>
        <author>tangshuo</author>
        <description>
          <![CDATA[
          <br/>
          作者: <a href="http://tangshuo.javaeye.com">tangshuo</a>&nbsp;
          链接：<a href="http://tangshuo.javaeye.com/blog/189820" style="color:red;">http://tangshuo.javaeye.com/blog/189820</a>&nbsp;
          发表时间: 2008年05月05日
          <br/><br/>
          声明：本文系JavaEye网站发布的原创博客文章，未经作者书面许可，严禁任何网站转载本文，否则必将追究法律责任！
          <br/><br/>
          <p>&nbsp;&nbsp;&nbsp; 上一篇结合Struts2实现了分页的自定义标签。标签比较简单，3个参数，单一的显示样式。下面对该标签的功能进行进一步的扩充，主要包括：</p>
<p>1.可以为标签指定样式。通过styleClass属性，可以为标签指定一个样式表。</p>
<p>2.增加了分页样式的选择。通过theme属性指定分页样式。</p>
<p>theme=&quot;text&quot;的样式：</p>
<p><img src="http://www.javaeye.com/upload/picture/pic/13653/dce14057-709a-3317-a3b3-ff6e62bbd362.bmp?1209892878" height="60" alt="" width="272" />
</p>
<p>theme=&quot;number&quot;的样式：</p>
<p><img src="http://www.javaeye.com/upload/picture/pic/13677/4e8f71c1-680b-3713-a673-a33ad98c9790.bmp?1209976573" height="75" alt="" width="206" />
</p>
<p><strong><span style="color: #0000ff; font-size: medium;">修改方案：</span>
</strong>
</p>
<p>1.在tld文件中增加这两个属性的声明：</p>
<pre name="code" class="xml">&lt;attribute&gt;
                &lt;name&gt;styleClass&lt;/name&gt;
                &lt;required&gt;false&lt;/required&gt;
                &lt;rtexprvalue&gt;true&lt;/rtexprvalue&gt;
&lt;/attribute&gt;
&lt;attribute&gt;
                &lt;name&gt;theme&lt;/name&gt;
                &lt;required&gt;false&lt;/required&gt;
                &lt;rtexprvalue&gt;true&lt;/rtexprvalue&gt;
&lt;/attribute&gt;</pre>
<p>&nbsp;2.在自定义标签类中分别增加styleClass和theme属性，并提供setter方法：</p>
<p>&nbsp;&nbsp; PageTag.java</p>
<pre name="code" class="java">/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.tangs.tag;

import com.opensymphony.xwork2.util.ValueStack;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.components.Component;
import org.apache.struts2.views.jsp.ComponentTagSupport;

/**
 * 分页标签
 * @author tangs
 */
public class PageTag extends ComponentTagSupport {
    private String cpage;
    private String total;
    private String url;
    private String styleClass;   //新增的样式属性
    private String theme;   //新增的分页样式属性
    
    public void setTheme(String theme) {
        this.theme = theme;
    }
    
    public void setStyleClass(String styleClass) {
        this.styleClass = styleClass;
    }

    public void setCpage(String cpage) {
        this.cpage = cpage;
    }

    public void setTotal(String total) {
        this.total = total;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @Override
    public Component getBean(ValueStack arg0, HttpServletRequest arg1, HttpServletResponse arg2) {
        return new Pages(arg0, arg1);
    }

    protected void populateParams() {
        super.populateParams();
        
        Pages pages = (Pages)component;
        pages.setCpage(cpage);
        pages.setTotal(total);
        pages.setUrl(url);
        pages.setStyleClass(styleClass);
        pages.setTheme(theme);

    }
}
</pre>
<p>&nbsp;&nbsp; Pages.java</p>
<pre name="code" class="java">/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.tangs.tag;

import com.opensymphony.xwork2.util.ValueStack;
import java.io.IOException;
import java.io.Writer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.components.Component;

/**
 * 分页逻辑Bean
 * @author tangs
 */
public class Pages extends Component {
    private HttpServletRequest request;
    private String cpage;
    private String total;
    private String url;
    private String styleClass;
    private String theme;
    
    public String getTheme() {
        return theme;
    }

    public void setTheme(String theme) {
        this.theme = theme;
    }
    
    
    public String getStyleClass() {
        return styleClass;
    }

    public void setStyleClass(String styleClass) {
        this.styleClass = styleClass;
    }

    
    public String getCpage() {
        return cpage;
    }

    public void setCpage(String cpage) {
        this.cpage = cpage;
    }

    public String getTotal() {
        return total;
    }

    public void setTotal(String total) {
        this.total = total;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
    
    
    public Pages(ValueStack arg0, HttpServletRequest request) {
        super(arg0);
        this.request = request;
    }

    @Override
    public boolean start(Writer writer) {
        boolean result = super.start(writer);
        try {
            StringBuilder str = new StringBuilder();
            boolean isValid = true;
            
            //从ValueStack中取出数值
            if (isValid) {
                if (total.startsWith(&quot;%{&quot;) &amp;&amp; total.endsWith(&quot;}&quot;)) {
                    total = total.substring(2, total.length() -1);
                    total = (String)this.getStack().findValue(total);
                    isValid = total == null ? false : true;
                } else {
                    isValid = false;
                }
            }
            if (isValid) {
                if (cpage.startsWith(&quot;%{&quot;) &amp;&amp; cpage.endsWith(&quot;}&quot;)) {
                    cpage = cpage.substring(2, cpage.length() - 1);
                    cpage = (String)this.getStack().findValue(cpage);
                    isValid = cpage == null ? false : true;
                } else {
                    isValid = false;
                }
            }
            if (isValid) {
                if (url.startsWith(&quot;%{&quot;) &amp;&amp; url.endsWith(&quot;}&quot;)) {
                    url = url.substring(2, url.length() - 1);
                    url = (String)this.getStack().findValue(url);
                    isValid = url == null ? false : true;
                } else {
                    isValid = false;
                }
            }

            if (isValid) {
                Integer cpageInt = Integer.valueOf(cpage);
                str.append(&quot;&lt;span &quot;);
                if (styleClass != null) {
                    str.append(&quot; class='&quot;+styleClass+&quot;'&gt;&quot;);
                } else {
                    str.append(&quot;&gt;&quot;);
                }
                
                //文本样式
                if (theme == null || &quot;text&quot;.equals(theme)) {  //theme=&quot;text&quot;样式
                    //当前页与总页数相等
                    if (cpage.equals(total)) {
                        //如果total = 1，则无需分页，显示“[第1页] [共1页]”
                        if (&quot;1&quot;.equals(total)) {
                            str.append(&quot;[第 &quot; + cpage + &quot; 页]&quot;);
                            str.append(&quot; [共 &quot; + total + &quot; 页]&quot;);
                        } else {
                            //到达最后一页,显示“[首页] [上一页] [末页]”
                            str.append(&quot;&lt;a href='&quot;);
                            str.append(url);
                            str.append(&quot;?cpage=1&amp;total=&quot;+total+&quot;&amp;url=&quot;+url);
                            str.append(&quot;'&gt;[首页]&lt;/a&gt; &lt;a href='&quot;);
                            str.append(url);
                            str.append(&quot;?cpage=&quot; + (cpageInt - 1) + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                            str.append(&quot;'&gt;[上一页]&lt;/a&gt; &lt;a href='&quot;);
                            str.append(url);
                            str.append(&quot;?cpage=&quot; + total + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                            str.append(&quot;'&gt;[末页]&lt;/a&gt;&quot;);
                        }
                    } else {
                        //当前页与总页数不相同
                        if (&quot;1&quot;.equals(cpage)) {
                            //第一页，显示“[首页] [下一页] [末页]”
                            str.append(&quot;&lt;a href='&quot;);
                            str.append(url);
                            str.append(&quot;?cpage=1&amp;total=&quot;+total+&quot;&amp;url=&quot;+url);
                            str.append(&quot;'&gt;[首页]&lt;/a&gt; &lt;a href='&quot;);
                            str.append(url);
                            str.append(&quot;?cpage=&quot; + (cpageInt + 1) + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                            str.append(&quot;'&gt;[下一页]&lt;/a&gt; &lt;a href='&quot;);
                            str.append(url);
                            str.append(&quot;?cpage=&quot; + total + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                            str.append(&quot;'&gt;[末页]&lt;/a&gt;&quot;);
                        } else {
                            //不是第一页，显示“[首页] [上一页] [下一页] [末页]”
                            str.append(&quot;&lt;a href='&quot;);
                            str.append(url);
                            str.append(&quot;?cpage=1&amp;total=&quot;+total+&quot;&amp;url=&quot;+url);
                            str.append(&quot;'&gt;[首页]&lt;/a&gt; &lt;a href='&quot;);
                            str.append(url);
                            str.append(&quot;?cpage=&quot; + (cpageInt - 1) + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                            str.append(&quot;'&gt;[上一页]&lt;/a&gt; &lt;a href='&quot;);
                            str.append(url);
                            str.append(&quot;?cpage=&quot; + (cpageInt + 1) + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                            str.append(&quot;'&gt;[下一页]&lt;/a&gt; &lt;a href='&quot;);
                            str.append(url);
                            str.append(&quot;?cpage=&quot; + total + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                            str.append(&quot;'&gt;[末页]&lt;/a&gt;&quot;);
                        }
                    }
                } else if (&quot;number&quot;.equals(theme)) {  //theme=&quot;number&quot;的数字样式 [1 2 3 4 5 6 7 8 9 10 &gt; &gt;&gt;]
                    Integer totalInt = Integer.valueOf(total);
                   
                    //如果只有一页，则无需分页
                    str.append(&quot;[ &quot;);
                    if (totalInt == 1) {
                        str.append(&quot;&lt;strong&gt;1&lt;/strong&gt; &quot;);
                    } else {
                        //计算一共分几组
                        int group = (totalInt - 1) / 10 + 1;
                        //当前第几组
                        int cgroup = (cpageInt - 1) / 10 + 1;
                        
                        if (cgroup &gt; 1) {
                            //当前不是第一组，要显示“&lt;&lt; &lt;”
                            //&lt;&lt;：返回前一组第一页
                            //&lt;：返回前一页
                            str.append(&quot;&lt;a href='&quot;);
                            str.append(url);
                            str.append(&quot;?cpage=&quot; + ((cgroup - 2) * 10 + 1 ) + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                            str.append(&quot;'&gt;«&lt;/a&gt; &quot; );
                            str.append(&quot;&lt;a href='&quot;);
                            str.append(url);
                            str.append(&quot;?cpage=&quot; + (cpageInt - 1) + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                            str.append(&quot;'&gt;‹&lt;/a&gt; &quot; );
                        }
                        //10个为一组显示
                        for (int i = (cgroup - 1) * 10 + 1; i &lt;= totalInt &amp;&amp; i &lt;= cgroup * 10; i++) {
                            if (cpageInt == i) { //当前页要加粗显示
                                str.append(&quot;&lt;strong&gt;&quot;);  
                            }
                            str.append(&quot;&lt;a href='&quot;);
                            str.append(url);
                            str.append(&quot;?cpage=&quot; + i + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                            str.append(&quot;'&gt;&quot; + i + &quot;&lt;/a&gt; &quot;);
                            if (cpageInt == i) {
                                str.append(&quot;&lt;/strong&gt;&quot;);
                            }
                        }
                        //如果多于1组并且不是最后一组，显示“&gt; &gt;&gt;”
                        if (group &gt; 1&amp;&amp; cgroup != group) {
                            //&gt;&gt;：返回下一组最后一页
                            //&gt;：返回下一页
                            str.append(&quot;&lt;a href='&quot;);
                            str.append(url);
                            str.append(&quot;?cpage=&quot; + (cpageInt + 1) + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                            str.append(&quot;'&gt;›&lt;/a&gt; &quot; );
                            str.append(&quot;&lt;a href='&quot;);
                            str.append(url);
                            str.append(&quot;?cpage=&quot; + ((cgroup * 10 + 10) &gt; totalInt ? totalInt : (cgroup * 10 + 10)) + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                            str.append(&quot;'&gt;»&lt;/a&gt; &quot; );
                        }
                    }
                    str.append(&quot;]&quot;);
                }
                str.append(&quot;&lt;/span&gt;&quot;);
            }
         
            writer.write(str.toString());
            
        } catch (IOException ex) {
            Logger.getLogger(Pages.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }
}
</pre>
<p>&nbsp;3.在页面中使用标签</p>
<pre name="code" class="html">&lt;tangs:pages cpage=&quot;%{cpage}&quot; total=&quot;%{total}&quot; url=&quot;%{url}&quot; styleClass=&quot;page&quot; theme=&quot;number&quot;/&gt;</pre>
<p>&nbsp;指定了styleClass和theme属性，得到的分页样式：</p>
<p><img src="http://www.javaeye.com/upload/picture/pic/13681/d5b062fe-76fe-35f3-99a2-686e5732ca84.bmp?1209977639" height="40" alt="" width="202" />
</p>
<p>&nbsp;</p>
          <br/>
          <span style="color:red;">
            <a href="http://tangshuo.javaeye.com/blog/189820#comments" style="color:red;">本文的讨论也很精彩，浏览讨论>></a>
          </span>
          <br/><br/><br/>
          <span style="color:#E28822;">JavaEye推荐</span>
          <br/>
          <ul class='adverts'><li><a href='/adverts/41' target='_blank'><span style="color:red;font-weight:bold;">北京: 千橡集团暨校内网诚聘软件研发工程师</span></a></li><li><a href='/adverts/42' target='_blank'><span style="color:red;font-weight:bold;">搜狐网站诚聘Java、PHP和C++工程师</span></a></li></ul>
          <br/><br/><br/>
          ]]>
        </description>
        <pubDate>Mon, 05 May 2008 16:55:03 +0800</pubDate>
        <link>http://tangshuo.javaeye.com/blog/189820</link>
        <guid>http://tangshuo.javaeye.com/blog/189820</guid>
      </item>
      <item>
        <title>Struts2中实现自定义分页标签</title>
        <author>tangshuo</author>
        <description>
          <![CDATA[
          <br/>
          作者: <a href="http://tangshuo.javaeye.com">tangshuo</a>&nbsp;
          链接：<a href="http://tangshuo.javaeye.com/blog/189447" style="color:red;">http://tangshuo.javaeye.com/blog/189447</a>&nbsp;
          发表时间: 2008年05月04日
          <br/><br/>
          声明：本文系JavaEye网站发布的原创博客文章，未经作者书面许可，严禁任何网站转载本文，否则必将追究法律责任！
          <br/><br/>
          <p>&nbsp;&nbsp;&nbsp; Struts2中实现自定义标签很简单，主要分为3步：</p>
<p>&nbsp;&nbsp;&nbsp; 1.创建taglib文件(.tld)，编写标签声明。</p>
<p>&nbsp;&nbsp;&nbsp; 2.编写自定义标签类。</p>
<p>&nbsp;&nbsp;&nbsp; 3.在页面中使用标签。</p>
<p>&nbsp;&nbsp;&nbsp; 下面以一个自定义的分页标签为例，进行说明。</p>
<p>&nbsp;&nbsp;&nbsp; 其实，开发自定义标签并不需要Struts2的支持，一般情况下，只需要继承javax.servlet.jsp.tagext.BodyTagSupport类，重写doStartTag，doEndTag等方法即可。这里在实现自定义标签时，继承的2个类分别是org.apache.struts2.views.jsp.ComponentTagSupport和org.apache.struts2.components.Component，ComponentTagSupport实际上是对BodyTagSupport的一次封装，看一下ComponentTagSupport类的继承关系就明了了：</p>
<pre name="code" class="java">java.lang.Object
  extended by javax.servlet.jsp.tagext.TagSupport
      extended by javax.servlet.jsp.tagext.BodyTagSupport
          extended by org.apache.struts2.views.jsp.StrutsBodyTagSupport
              extended by org.apache.struts2.views.jsp.ComponentTagSupport

</pre>
<p>&nbsp;继承ComponentTagSupport类是为了获得标签中的属性值，并包装成Component对象。继承Component类是为了从Struts2中的ValueStack中获得相对应的值。</p>
<p>1.声明自定义标签。</p>
<p>首先，需要创建一个tld文件，这是一个标准的XML文件，这个文件中就包含有对自定义标签的声明，声明指出了标签的名字，实现标签的类，标签的属性等信息。当在页面中使用该标签时，web服务器就会从这个文件中找出相对应的标签类，并实例化后执行。这个文件其实与struts.xml文件的作用相类似。</p>
<p>tangs.tld</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE taglib PUBLIC &quot;-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN&quot; &quot;http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd&quot;&gt;
&lt;taglib&gt;
	&lt;tlib-version&gt;2.2.3&lt;/tlib-version&gt;
	&lt;jsp-version&gt;1.2&lt;/jsp-version&gt;
	&lt;short-name&gt;tangs&lt;/short-name&gt;
	&lt;uri&gt;/tangs&lt;/uri&gt;
	&lt;display-name&gt;&quot;Tangs Tags&quot;&lt;/display-name&gt;
	
        &lt;tag&gt;
            &lt;name&gt;pages&lt;/name&gt;
            &lt;tag-class&gt;com.tangs.tag.PageTag&lt;/tag-class&gt;   //标签类
            &lt;body-content&gt;empty&lt;/body-content&gt;
            &lt;attribute&gt;   //标签中的属性
                &lt;name&gt;cpage&lt;/name&gt;  //属性名
                &lt;required&gt;true&lt;/required&gt;  //是否必须
                &lt;rtexprvalue&gt;true&lt;/rtexprvalue&gt;  //表示该自定义标签的某属性的值可以直接指定或者通过动态计算指定
            &lt;/attribute&gt;
            &lt;attribute&gt;
                &lt;name&gt;total&lt;/name&gt;
                &lt;required&gt;true&lt;/required&gt;
                &lt;rtexprvalue&gt;true&lt;/rtexprvalue&gt;
            &lt;/attribute&gt;
            &lt;attribute&gt;
                &lt;name&gt;url&lt;/name&gt;
                &lt;required&gt;true&lt;/required&gt;
                &lt;rtexprvalue&gt;true&lt;/rtexprvalue&gt;
            &lt;/attribute&gt;
        &lt;/tag&gt;
&lt;/taglib&gt;
</pre>
<p>&nbsp;2.编写标签类</p>
<p>PageTag.java</p>
<pre name="code" class="java">package com.tangs.tag;

import com.opensymphony.xwork2.util.ValueStack;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.components.Component;
import org.apache.struts2.views.jsp.ComponentTagSupport;

/**
 * 分页标签
 * @author tangs
 */
public class PageTag extends ComponentTagSupport {
    private String cpage;  //当前页
    private String total;  //总页数
    private String url;  //请求地址

    public void setCpage(String cpage) {
        this.cpage = cpage;
    }

    public void setTotal(String total) {
        this.total = total;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @Override
    public Component getBean(ValueStack arg0, HttpServletRequest arg1, HttpServletResponse arg2) {
        return new Pages(arg0); //返回Pages Component，分页的逻辑处理都在这个Component中
    }

    //获得参数
    protected void populateParams() {
        super.populateParams();
        
        Pages pages = (Pages)component;
        pages.setCpage(cpage);
        pages.setTotal(total);
        pages.setUrl(url);
    }
}
</pre>
<p>&nbsp;&nbsp;&nbsp; Pages.java</p>
<pre name="code" class="java">package com.tangs.tag;

import com.opensymphony.xwork2.util.ValueStack;
import java.io.IOException;
import java.io.Writer;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.struts2.components.Component;

/**
 * 分页逻辑Bean
 * @author tangs
 */
public class Pages extends Component {
    private String cpage;
    private String total;
    private String url;

    public String getCpage() {
        return cpage;
    }

    public void setCpage(String cpage) {
        this.cpage = cpage;
    }

    public String getTotal() {
        return total;
    }

    public void setTotal(String total) {
        this.total = total;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
    
    
    public Pages(ValueStack arg0) {
        super(arg0);
    }

    @Override
    public boolean start(Writer writer) {
        boolean result = super.start(writer);
        try {
            StringBuilder str = new StringBuilder();
            boolean isValid = true;
            
            //从ValueStack中取出数值
            if (isValid) {
                if (total.startsWith(&quot;%{&quot;) &amp;&amp; total.endsWith(&quot;}&quot;)) {
                    total = total.substring(2, total.length() -1);
                    total = (String)this.getStack().findValue(total);
                    isValid = total == null ? false : true;
                } else {
                    isValid = false;
                }
            }
            if (isValid) {
                if (cpage.startsWith(&quot;%{&quot;) &amp;&amp; cpage.endsWith(&quot;}&quot;)) {
                    cpage = cpage.substring(2, cpage.length() - 1);
                    cpage = (String)this.getStack().findValue(cpage);
                    isValid = cpage == null ? false : true;
                } else {
                    isValid = false;
                }
            }
            if (isValid) {
                if (url.startsWith(&quot;%{&quot;) &amp;&amp; url.endsWith(&quot;}&quot;)) {
                    url = url.substring(2, url.length() - 1);
                    url = (String)this.getStack().findValue(url);
                    isValid = url == null ? false : true;
                } else {
                    isValid = false;
                }
            }

            if (isValid) {
                Integer cpageInt = Integer.valueOf(cpage);
                //当前页与总页数相等
                if (cpage.equals(total)) {
                    //如果total = 1，则无需分页，显示“[第1页] [共1页]”
                    if (&quot;1&quot;.equals(total)) {
                        str.append(&quot;[第 &quot; + cpage + &quot; 页]&quot;);
                        str.append(&quot; [共 &quot; + total + &quot; 页]&quot;);
                    } else {
                        //到达最后一页,显示“[首页] [上一页] [末页]”
                        str.append(&quot;&lt;a href='&quot;);
                        str.append(url);
                        str.append(&quot;?cpage=1&amp;total=&quot;+total+&quot;&amp;url=&quot;+url);
                        str.append(&quot;'&gt;[首页]&lt;/a&gt; &lt;a href='&quot;);
                        str.append(url);
                        str.append(&quot;?cpage=&quot; + (cpageInt - 1) + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                        str.append(&quot;'&gt;[上一页]&lt;/a&gt; &lt;a href='&quot;);
                        str.append(url);
                        str.append(&quot;?cpage=&quot; + total + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                        str.append(&quot;'&gt;[末页]&lt;/a&gt;&quot;);
                    }
                } else {
                    //当前页与总页数不相同
                    if (&quot;1&quot;.equals(cpage)) {
                        //第一页，显示“[首页] [下一页] [末页]”
                        str.append(&quot;&lt;a href='&quot;);
                        str.append(url);
                        str.append(&quot;?cpage=1&amp;total=&quot;+total+&quot;&amp;url=&quot;+url);
                        str.append(&quot;'&gt;[首页]&lt;/a&gt; &lt;a href='&quot;);
                        str.append(url);
                        str.append(&quot;?cpage=&quot; + (cpageInt + 1) + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                        str.append(&quot;'&gt;[下一页]&lt;/a&gt; &lt;a href='&quot;);
                        str.append(url);
                        str.append(&quot;?cpage=&quot; + total + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                        str.append(&quot;'&gt;[末页]&lt;/a&gt;&quot;);
                    } else {
                        //不是第一页，显示“[首页] [上一页] [下一页] [末页]”
                        str.append(&quot;&lt;a href='&quot;);
                        str.append(url);
                        str.append(&quot;?cpage=1&amp;total=&quot;+total+&quot;&amp;url=&quot;+url);
                        str.append(&quot;'&gt;[首页]&lt;/a&gt; &lt;a href='&quot;);
                        str.append(url);
                        str.append(&quot;?cpage=&quot; + (cpageInt - 1) + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                        str.append(&quot;'&gt;[上一页]&lt;/a&gt; &lt;a href='&quot;);
                        str.append(url);
                        str.append(&quot;?cpage=&quot; + (cpageInt + 1) + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                        str.append(&quot;'&gt;[下一页]&lt;/a&gt; &lt;a href='&quot;);
                        str.append(url);
                        str.append(&quot;?cpage=&quot; + total + &quot;&amp;total=&quot; + total+&quot;&amp;url=&quot;+url);
                        str.append(&quot;'&gt;[末页]&lt;/a&gt;&quot;);
                    }
                }
            }
           
            writer.write(str.toString());
            
        } catch (IOException ex) {
            Logger.getLogger(Pages.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }
}
</pre>
<p>3.服务端</p>
<p>服务端主要是获得请求然后转向显示的页面</p>
<p>DisplayAction.java</p>
<pre name="code" class="java">/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.tangs.action;

import com.opensymphony.xwork2.ActionSupport;

/**
 *
 * @author tangs
 */
public class DisplayAction extends ActionSupport {
    private String cpage;
    private String total;
    private String url;

    public String list() {
        
        //Get data from server
        //...
        //这里没有做任何逻辑，直接跳转到了页面
        return SUCCESS;
    }
    public String getCpage() {
        return cpage;
    }

    public void setCpage(String cpage) {
        this.cpage = cpage;
    }

    public String getTotal() {
        return total;
    }

    public void setTotal(String total) {
        this.total = total;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
    
    
}
</pre>
<p>&nbsp; struts.xml</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE struts PUBLIC &quot;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&quot; &quot;http://struts.apache.org/dtds/struts-2.0.dtd&quot; &gt;
&lt;struts&gt;
	&lt;package name=&quot;tagTest&quot; extends=&quot;struts-default&quot;&gt;
                &lt;action name=&quot;list&quot; class=&quot;com.tangs.action.DisplayAction&quot;&gt;
                    &lt;result name=&quot;success&quot;&gt;/list.jsp&lt;/result&gt;
                &lt;/action&gt;
	&lt;/package&gt;
&lt;/struts&gt;
</pre>
&nbsp;
<p>4.在页面中使用标签</p>
<p>list.jsp</p>
<pre name="code" class="html">&lt;%@page contentType=&quot;text/html&quot; pageEncoding=&quot;UTF-8&quot;%&gt;
&lt;%@ taglib prefix=&quot;tangs&quot; uri=&quot;/WEB-INF/tangs.tld&quot;%&gt;
&lt;%@ taglib prefix=&quot;s&quot; uri=&quot;/WEB-INF/struts-tags.tld&quot;%&gt;

&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
        &lt;title&gt;List&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        共 &lt;s:property value=&quot;total&quot;/&gt; 页 第 &lt;s:property value=&quot;cpage&quot;/&gt; 页&lt;br&gt;
        &lt;tangs:pages cpage=&quot;%{cpage}&quot; total=&quot;%{total}&quot; url=&quot;%{url}&quot;/&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>&nbsp;</p>
<p>好了，启动服务器，从浏览器中输入http://localhost:7001/TagTest/list.page?cpage=1&amp;total=5&amp;url=list.page</p>
<p>就会得到下面的结果：</p>
<p><img src="http://www.javaeye.com/upload/picture/pic/13651/714bdf9e-7b3a-3e59-9c67-5e6f9edac63f.bmp?1209892866" height="57" alt="" width="205" />
</p>
<p><img src="http://www.javaeye.com/upload/picture/pic/13653/dce14057-709a-3317-a3b3-ff6e62bbd362.bmp?1209892878" height="60" alt="" width="272" />
</p>
<p><img src="http://www.javaeye.com/upload/picture/pic/13655/ce9490d2-6a45-393d-9453-2e21ab84dde2.bmp?1209892884" height="60" alt="" width="205" />
</p>
          <br/>
          <span style="color:red;">
            <a href="http://tangshuo.javaeye.com/blog/189447#comments" style="color:red;">本文的讨论也很精彩，浏览讨论>></a>
          </span>
          <br/><br/><br/>
          <span style="color:#E28822;">JavaEye推荐</span>
          <br/>
          <ul class='adverts'><li><a href='/adverts/42' target='_blank'><span style="color:red;font-weight:bold;">搜狐网站诚聘Java、PHP和C++工程师</span></a></li><li><a href='/adverts/41' target='_blank'><span style="color:red;font-weight:bold;">北京: 千橡集团暨校内网诚聘软件研发工程师</span></a></li></ul>
          <br/><br/><br/>
          ]]>
        </description>
        <pubDate>Sun, 04 May 2008 17:23:27 +0800</pubDate>
        <link>http://tangshuo.javaeye.com/blog/189447</link>
        <guid>http://tangshuo.javaeye.com/blog/189447</guid>
      </item>
      <item>
        <title>用MXML开发Flex应用－ Basic MXML syntax</title>
        <author>tangshuo</author>
        <description>
          <![CDATA[
          <br/>
          作者: <a href="http://tangshuo.javaeye.com">tangshuo</a>&nbsp;
          链接：<a href="http://tangshuo.javaeye.com/blog/188391" style="color:red;">http://tangshuo.javaeye.com/blog/188391</a>&nbsp;
          发表时间: 2008年04月30日
          <br/><br/>
          声明：本文系JavaEye网站发布的原创博客文章，未经作者书面许可，严禁任何网站转载本文，否则必将追究法律责任！
          <br/><br/>
          <h1> Basic MXML syntax</h1>
<p>&nbsp;MXML基本语法</p>
<!--   googleoff: index--><!--    END PAGE TITLE --><!--    BEGIN CONTENT WRAPPER -->
  
  
  
    <!--   googleon: index-->
<p>Most MXML tags correspond to ActionScript 3.0 classes or properties
of classes. Flex parses MXML tags and compiles a SWF file that contains
the corresponding ActionScript objects.</p>
<p>许多MXML标签其实就是ActionScript3.0的类或类的属性。Flex解析MXML标签并编译成一个包含ActionScript对象的SWF文件。</p>
<p>ActionScript 3.0 uses
syntax based on the ECMAScript edition 4 draft language specification.
ActionScript 3.0 includes the following features:</p>
<p>ActionScript3.0语法基于ECMActionScript edtion 4 草稿说明。</p>
<ul>
<li>Formal class definition syntax</li>
<li>Formal packages structure</li>
<li>Typing of variables, parameters, and return values (compile-time only)</li>
<li>Implicit getters and setters that use the <samp class="codeph">get</samp>

 and <samp class="codeph">set</samp>

 keywords
</li>
<li>Inheritance
</li>
<li>Public and private members
</li>
<li>Static members
</li>
<li>Cast operator</li>
</ul>
<h2 class="h2nobreak">Naming MXML files</h2>
<h2 class="h2nobreak">MXML文件命名<br />
</h2>
<p>MXML filenames must adhere to the following naming conventions:</p>
<p>MXML文件名必须遵守以下规定：</p>
<ul>
<li>Filenames
must be valid ActionScript identifiers, which means they must start
with a letter or underscore character (_), and they can only contain
letters, numbers, and underscore characters after that.</li>
<li>文件名必须是合法的ActionScript标识符，也就是说，必须以字母或下划线开头，只能包含字符、数字和下划线。</li>
<li>Filenames must not be the same as ActionScript class names, component <samp class="codeph">id</samp>
 values, or the word <em>application</em>
. Do not use filenames that match the names of MXML tags that are in the mx namespace.</li>
<li>文件名不能与ActionScript类名，组件id或应用程序名相同。不要用于mx命名空间中的MXML标签名做文件名。</li>
<li>Filenames must end with a lowercase .mxml file extension.</li>
<li>文件名必须以小写.mxml扩展名结束</li>
</ul>
<h2 class="h2nobreak">Using tags that represent ActionScript classes</h2>
<h2 class="h2nobreak">用标签做ActionScript类<br />
</h2>
<p>An MXML tag that corresponds to an ActionScript class uses the same
naming conventions as the ActionScript class. Class names begin with a
capital letter, and capital letters separate the words in class names.
For example, when a tag corresponds to an ActionScript class, its
properties correspond to the properties and events of that class.</p>
<p>一个MXML标签相对于一个以相同名称命名的ActionScript类。类名以一个大写字母开头，大写字母用来分隔单词。例如，当一个标签相对于一个ActionScript类时，它的属性就相当于那个类的属性或事件方法。</p>
          <br/>
          <span style="color:red;">
            <a href="http://tangshuo.javaeye.com/blog/188391#comments" style="color:red;">本文的讨论也很精彩，浏览讨论>></a>
          </span>
          <br/><br/><br/>
          <span style="color:#E28822;">JavaEye推荐</span>
          <br/>
          <ul class='adverts'><li><a href='/adverts/41' target='_blank'><span style="color:red;font-weight:bold;">北京: 千橡集团暨校内网诚聘软件研发工程师</span></a></li><li><a href='/adverts/42' target='_blank'><span style="color:red;font-weight:bold;">搜狐网站诚聘Java、PHP和C++工程师</span></a></li></ul>
          <br/><br/><br/>
          ]]>
        </description>
        <pubDate>Wed, 30 Apr 2008 13:53:50 +0800</pubDate>
        <link>http://tangshuo.javaeye.com/blog/188391</link>
        <guid>http://tangshuo.javaeye.com/blog/188391</guid>
      </item>
      <item>
        <title>用MXML开发Flex应用－Developing applications</title>
        <author>tangshuo</author>
        <description>
          <![CDATA[
          <br/>
          作者: <a href="http://tangshuo.javaeye.com">tangshuo</a>&nbsp;
          链接：<a href="http://tangshuo.javaeye.com/blog/188322" style="color:red;">http://tangshuo.javaeye.com/blog/188322</a>&nbsp;
          发表时间: 2008年04月30日
          <br/><br/>
          声明：本文系JavaEye网站发布的原创博客文章，未经作者书面许可，严禁任何网站转载本文，否则必将追究法律责任！
          <br/><br/>
          <h1> Developing applications</h1>
<p>开发应用程序</p>
<p>MXML development is based on the same iterative process used for other
types of web application files such as HTML, JavaServer Pages (JSP),
Active Server Pages (ASP), and ColdFusion Markup Language (CFML).
Developing a useful Flex application is as easy as opening your
favorite text editor, typing some XML tags, saving the file, requesting
the file's URL in a web browser, and then repeating the same process.</p>
<p>MXML开发与其他的Web应用开发相似，比如HTML，JavaServer Pages(JSP)，Active Service Pages(ASP)和ColdFunsion Markup Language (CFML)。开发一个Flex应用很简单，打开你的文本编辑器，输入一些XML标签，保存这个文件，然后将这个文件的URL放到浏览器上，就可以看到结果了。</p>
<h2 class="h2nobreak">Laying out a user interface using containers</h2>
<p>通过容器设计用户接口</p>
<p>In the Flex model-view design pattern, user interface components
represent the view. The MXML language supports two types of user
interface components: controls and containers. Controls are form
elements, such as buttons, text fields, and list boxes. Containers are
rectangular regions of the screen that contain controls and other
containers.</p>
<p>在Flex的模型-视图设计模式中，用户接口组件在视图中展示出来。MXML语言支持两种类型的用户接口组件：控制组件和容器组件。控制组件是一些表单元素，如butttons, text fileds和list boxes。容器是包含了控制组件和其他容器的一个矩形的区域。</p>
<p>You use container components for laying out a user interface, and for
controlling user navigation through the application. Examples of layout
containers include the <a href="http://livedocs.adobe.com/flex/3/langref/mx/containers/HBox.html" target="_blank">HBox</a>
 container for laying out child components horizontally, the <a href="http://livedocs.adobe.com/flex/3/langref/mx/containers/VBox.html" target="_blank">VBox</a>
 container for laying out child components vertically, and the <a href="http://livedocs.adobe.com/flex/3/langref/mx/containers/Grid.html" target="_blank">Grid</a>
 container for laying out child components in rows and columns. Examples of navigator containers include the <a href="http://livedocs.adobe.com/flex/3/langref/mx/containers/TabNavigator.html" target="_blank">TabNavigator</a>
 container for creating tabbed panels, the Accordion navigator container for creating collapsible panels, and the <a href="http://livedocs.adobe.com/flex/3/langref/mx/containers/ViewStack.html" target="_blank">ViewStack</a>
 navigator container for laying out panels on top of each other.</p>
<p>你可以用容器组件去设计用户接口，在应用中控制用户的操作。比如说，布局容器包括HBox容器，它是用来将子组件水平摆放，VBox容器将子组件垂直摆放，Grid容器将子组件以行列的形式展示。导航容器的例子有TabNavigator容器，它用来创建Tab面板，Accordion容器用来创建可伸展的面板，ViewStack导航容器将面板相互叠加。</p>
<p>The <a href="http://livedocs.adobe.com/flex/3/langref/mx/core/Container.html" target="_blank">Container</a>
class is the base class of all Flex container classes. Containers that
extend the Container class add their own functionality for laying out
child components. Typical properties of a container tag include <samp class="codeph">id</samp>
, <samp class="codeph">width</samp>
, and <samp class="codeph">height</samp>
. </p>
<p>Container类是所有Flex容器的基类。容器通过集成Container class，增加自己的功能，来实现子容器。典型的容器标签包括id,width和height。</p>
<p>
<object height="300" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="500">
<param name="src" value="http://livedocs.adobe.com/flex/3/html/movies/LayoutExample.swf" />
<embed src="http://livedocs.adobe.com/flex/3/html/movies/LayoutExample.swf" type="application/x-shockwave-flash" height="300" width="500"></embed>
</object>
</p>
<p>The <a href="http://livedocs.adobe.com/flex/3/langref/mx/controls/List.html" target="_blank">List</a>
control and TabNavigator container are laid out side by side because
they are in an HBox container. The controls in the TabNavigator
container are laid out from top to bottom because they are in a VBox
container.</p>
<p>List标签容器与TabNavigator容器分别在各自的旁边，因为它们在一个HBox容器中。在TabNavigator中的容器是从上到下排列，因为它们在一个VBox容器中。</p>
<h2 class="h2nobreak">Adding user interface controls</h2>
<p>添加用户控制接口</p>
<p>Flex includes a large selection of user interface components, such as <a href="http://livedocs.adobe.com/flex/3/langref/mx/controls/Button.html" target="_blank">Button</a>
, <a href="http://livedocs.adobe.com/flex/3/langref/mx/controls/TextInput.html" target="_blank">TextInput</a>
, and <a href="http://livedocs.adobe.com/flex/3/langref/mx/controls/ComboBox.html" target="_blank">ComboBox</a>
controls. After you define the layout and navigation of your
application by using container components, you add the user interface
controls.</p>
<p>Flex包含了许多用户接口组件，比如Button,TextInput和ComboBox等。当你定义好了应用的界面布局并且通过容器组件来控制你的应用时，你就添加了用户控制接口。</p>
<p>The following example contains an HBox (horizontal box) container with
two child controls, a TextInput control and a Button control. An <a href="http://livedocs.adobe.com/flex/3/langref/mx/containers/HBox.html" target="_blank">HBox</a>
 container lays out its children horizontally.</p>
<p>下面这例子是一个包含有两个子控制组件，一个TextInput，一个Button的HBox容器。HBox容器将它的子容器横向排放。</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!-- mxml/AddUIControls.mxml --&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
    &lt;mx:Script&gt;
        &lt;![CDATA[
            private function storeZipInDatabase(s:String):void {
                // event handler code here
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:HBox&gt;
        &lt;mx:TextInput id=&quot;myText&quot;/&gt;
        &lt;mx:Button click=&quot;storeZipInDatabase(myText.text)&quot;/&gt;
    &lt;/mx:HBox&gt;

&lt;/mx:Application&gt;</pre>
<p>&nbsp;
<object height="100" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="300">
<param name="src" value="http://livedocs.adobe.com/flex/3/html/movies/AddUIControls.swf" />
<embed src="http://livedocs.adobe.com/flex/3/html/movies/AddUIControls.swf" type="application/x-shockwave-flash" height="100" width="300"></embed>
</object>
</p>
<p>Typical properties of a control tag include <samp class="codeph">id</samp>
, <samp class="codeph">width</samp>
, <samp class="codeph">height</samp>
, <samp class="codeph">fontSize</samp>
, <samp class="codeph">color</samp>
, event listeners for events such as <samp class="codeph">click</samp>
 and <samp class="codeph">change</samp>
, and effect triggers such as<samp class="codeph"> showEffect</samp>
 and <samp class="codeph">rollOverEffect.</samp>
<samp class="codeph"><br />
</samp>
<samp class="codeph">一个典型的控制标签包括id,width,height,fontSize,color,event listeners（如click和change），还有效果触发器，如showEffect何rollOverEffect等。</samp>
<samp class="codeph"><br />
</samp>
</p>
<h2 class="h2nobreak">Using the id property with MXML tags</h2>
<p>在MXML中使用id属性</p>
<p>With a few exceptions (see <a href="http://livedocs.adobe.com/flex/3/html/mxmlSyntax_3.html#144554">MXML tag rules</a>
), an MXML tag has an optional <samp class="codeph">id</samp>
 property, which must be unique within the MXML file. If a tag has an <samp class="codeph">id</samp>
property, you can reference the corresponding object in ActionScript.</p>
<p>除了很少一部分标签，一个MXML标签都有一个可选的id属性。这个id属性，在一个MXML文件中必须唯一。如果一个标签包含有id属性，那么，你可以在ActionScript中通过这个id去直接引用这标签对象。</p>
<p>In the following example, results from a web-service request are traced in the <samp class="codeph">writeToLog</samp>
 function:</p>
<p>下面的例子中，一个通过web-service请求回来的数据通过writeToLog方法被记录下来：</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!-- mxml/UseIDProperty.mxml --&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
    &lt;mx:VBox&gt;
        &lt;mx:TextInput id=&quot;myText&quot; text=&quot;Hello World!&quot; /&gt;
        &lt;mx:Button id=&quot;mybutton&quot; label=&quot;Get Weather&quot; click=&quot;writeToLog();&quot;/&gt;
    &lt;/mx:VBox&gt;
    &lt;mx:Script&gt;
        &lt;![CDATA[
            private function writeToLog():void          {
                trace(myText.text);
            }
        ]]&gt;
    &lt;/mx:Script&gt;
&lt;/mx:Application&gt;</pre>
<p>&nbsp;
<object height="100" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="300">
<param name="src" value="http://livedocs.adobe.com/flex/3/html/movies/UseIDProperty.swf" />
<embed src="http://livedocs.adobe.com/flex/3/html/movies/UseIDProperty.swf" type="application/x-shockwave-flash" height="100" width="300"></embed>
</object>
</p>
<p>This code causes the MXML compiler to autogenerate a public variable named <samp class="codeph">myText</samp>
 that contains a reference to that <a href="http://livedocs.adobe.com/flex/3/langref/mx/controls/TextInput.html" target="_blank">TextInput</a>
instance. This autogenerated variable lets you access the component
instance in ActionScript. You can explicitly refer to the TextInput
control's instance with its <samp class="codeph">id</samp>
instance
reference in any ActionScript class or script block. By referring to a
component's instance, you can modify its properties and call its
methods.</p>
<p>这段代码会让MXML编译器生成一个名叫myText的公共的变量，这个变量指向了那个TextInput实例。这个自动生成的变量可以让你在ActionScript中访问它所指向的实例。你可以在ActionScript类或script块中通过这id直接操作那个TextInput实例。通过这个指向容器实例的引用，你可以修改它的属性调用它的方法。</p>
<p>Because each <samp class="codeph">id</samp>
 value in an
MXML file is unique, all objects in a file are part of the same flat
namespace. You do not qualify an object by referencing its parent with
dot notation, as in <samp class="codeph">myVBox.myText.text.</samp>
<samp class="codeph"><br />
</samp>
<samp class="codeph">由于一个MXML文件中每一个id都是唯一的，一个文件中的所有的对象都是同一个命名空间的一部分。因此，你不需要在引用一个对象时在前面指定它的父对象。<br />
</samp>
</p>
<h2 class="h2nobreak">Using XML namespaces</h2>
<p>使用XML命名空间</p>
<p>In an XML document, tags are associated with a namespace. XML
namespaces let you refer to more than one set of XML tags in the same
XML document. The <samp class="codeph">xmlns</samp>
property in an
MXML tag specifies an XML namespace. To use the default namespace,
specify no prefix. To use additional tags, specify a tag prefix and a
namespace.</p>
<p>在一个XML文件中，标签是与命名空间相关联的。XML命名空间可以让你在同一个XML文件中引用更多的XML标签。在MXML标签中，xmlns属性指定了XML命名空间。如果要用默认的命名空间，不要加前缀。要用额外的标签，需要制定标签的前缀和命名空间。</p>
<p>For example, the <samp class="codeph">xmlns</samp>
 property in the following <samp class="codeph">&lt;mx:Application&gt;</samp>
 tag indicates that tags in the MXML namespace use the prefix <em>mx:</em>
. The Universal Resource Identifier (URI) for the MXML namespace is http://www.adobe.com/2006/mxml.</p>
<p>例如，在下面的&lt;mx:Application&gt;标签中的xmlns属性指定了命名空间mx。这个MXML命名空间的URI是http://www.adobe.com/2006/mxml。</p>
<pre name="code" class="xml">&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;</pre>
<p>&nbsp;XML namespaces give you the ability to use custom tags that are not in
the MXML namespace. The following example shows an application that
contains a custom tag called CustomBox. The namespace value<samp> </samp>
containers.boxes.*</p>
<samp class="codeph"></samp>
<p>indicates that an MXML component called CustomBox is in the containers/boxes directory.</p>
<p>XML命名空间可以让你使用不在MXML命名空间的自定义的标签。下面这个例子展示了一个叫CustomBox的自定义标签。这个命名空间containers.boxes.*指定了一个叫CustomBox的组件在containers/boxes目录下。</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!-- mxml/XMLNamespaces.mxml --&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; 
    xmlns:MyComps=&quot;containers.boxes.*&quot;
&gt;
    &lt;mx:Panel title=&quot;My Application&quot; 
        paddingTop=&quot;10&quot; 
        paddingBottom=&quot;10&quot;
        paddingLeft=&quot;10&quot; 
        paddingRight=&quot;10&quot;
    &gt;
        &lt;MyComps:CustomBox/&gt;
    &lt;/mx:Panel&gt;
&lt;/mx:Application&gt;</pre>
<p>
<object height="200" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="200">
<param name="src" value="http://livedocs.adobe.com/flex/3/html/movies/XMLNamespaces.swf" />
<embed src="http://livedocs.adobe.com/flex/3/html/movies/XMLNamespaces.swf" type="application/x-shockwave-flash" height="200" width="200"></embed>
</object>
</p>
<p>The containers/boxes directory can be a subdirectory of the
directory that contains the application file, or it can be a
subdirectory of one of the ActionScript source path directories
assigned in the flex-config.xml file. If copies of the same file exist
in both places, Flex uses the file in the application file directory.
The prefix name is arbitrary, but it must be used as declared.</p>
<p>containers/boxes路径可以是一个包含应用文件路径的子路径，也可以是一个在flex-config.xml文件中指定的ActionScript源文件路径的子路径。如果在这两个路径下都包含这个文件，Flex使用的是应用程序文件路径。前缀名可以是任意的，但是用的时候必须和声明时的一样。</p>
<p>When
using a component contained in a SWC file, the package name and the
namespace must match, even though the SWC file is in the same directory
as the MXML file that uses it. A SWC file is an archive file for Flex
components. SWC files make it easy to exchange components among Flex
developers. You exchange only a single file, rather than the MXML or
ActionScript files and images, along with other resource files. Also,
the SWF file inside a SWC file is compiled, which means that the code
is obfuscated from casual view.</p>
<p>当使用了一个包含在SWC文件中的组件时，包名与命名空间必须相符，即使这个SWC文件与要使用它的MXML文件在同一路径下。SWC文件是一个Flex组件的存档文件。SWC文件使得组件在Flex开发者的相互使用中更加方便。你只需要用一个SWC文件，而不是MXML或ActionScript类，以及图片等其他资源文件进行交互。另外，SWC文件中的SWF文件经过了编译，也就是说在一般的视图下打开SWC文件，看到的将是乱码。</p>
<h2 class="h2nobreak">Using MXML to trigger run-time code</h2>
<p>用MXML触发运行时代码</p>
<p>Flex applications are driven by run-time events, such as when a user selects a <a href="http://livedocs.adobe.com/flex/3/langref/mx/controls/Button.html" target="_blank">Button</a>
 control. You can specify <em>event listeners</em>
, which consist of code for handling run-time events, in the event properties of MXML tags. For example, the <samp class="codeph">&lt;mx:Button&gt;</samp>
 tag has a <samp class="codeph">click</samp>
event property in which you can specify ActionScript code that executes
when the Button control is clicked at run time. You can specify simple
event listener code directly in event properties. To use more complex
code, you can specify the name of an ActionScript function defined in
an <samp class="codeph">&lt;mx:Script&gt;</samp>
tag.</p>
<p>Flex应用是由运行时的事件驱动的，如当一个用户选择了一个Button控制组件，你可以通过MXML标签的事件属性编写事件监听器，来处理运行时的事件。如：&lt;mx:Button&gt;标签有一个click事件属性，通过这个属性，你可以用一段ActionScript代码控制当这个button在运行时被点击后的动作。你可以直接在事件属性中编写简单的事件监听器。如果要用更复杂的代码，你可以在事件属性中指定监听器的名字，这个监听器被定义在&lt;mx:Script&gt;标签中。</p>
<p>The following example shows an application that contains a Button control and a <a href="http://livedocs.adobe.com/flex/3/langref/mx/controls/TextArea.html" target="_blank">TextArea</a>
 control. The <samp class="codeph">click</samp>
 property of the Button control contains a simple event listener that sets the value of the TextArea control's <samp class="codeph">text</samp>
 property to the text <samp class="codeph">Hello World。</samp>
<samp class="codeph"><br />
</samp>
<samp class="codeph">下面这个例子展现的是一个包含了一个Button和一个TextArea的应用。Button组件的click属性指定一个监听器，它会将TexaArea的text属性设置为Hello,World。</samp>
<samp class="codeph"><br />
</samp>
</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!-- mxml/TriggerCodeExample.mxml --&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
    &lt;mx:Panel title=&quot;My Application&quot; 
        paddingTop=&quot;10&quot; 
        paddingBottom=&quot;10&quot;
        paddingLeft=&quot;10&quot; 
        paddingRight=&quot;10&quot;
    &gt;
        &lt;mx:TextArea id=&quot;textarea1&quot;/&gt;
        &lt;mx:Button label=&quot;Submit&quot; click=&quot;textarea1.text='Hello World';&quot;/&gt;
    &lt;/mx:Panel&gt;
&lt;/mx:Application&gt;</pre>
<p>&nbsp;
<object height="200" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="300">
<param name="src" value="http://livedocs.adobe.com/flex/3/html/movies/TriggerCodeExample.swf" />
<embed src="http://livedocs.adobe.com/flex/3/html/movies/TriggerCodeExample.swf" type="application/x-shockwave-flash" height="200" width="300"></embed>
</object>
</p>
<p>The following example shows the code for a version of the application
in which the event listener is contained in an ActionScript function in
an <samp class="codeph">&lt;mx:Script&gt;</samp>
tag:</p>
<p>下面是一段包含在&lt;mx:Script&gt;标签中定义的监听器代码：</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!-- mxml/TriggerCodeExample2.mxml --&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
    &lt;mx:Script&gt;
        &lt;![CDATA[
            private function hello():void {
                textarea1.text=&quot;Hello World&quot;;
            }
        ]]&gt;
    &lt;/mx:Script&gt;
    &lt;mx:Panel title=&quot;My Application&quot; 
        paddingTop=&quot;10&quot; 
        paddingBottom=&quot;10&quot;
        paddingLeft=&quot;10&quot; 
        paddingRight=&quot;10&quot;
    &gt;
        &lt;mx:TextArea id=&quot;textarea1&quot;/&gt;
        &lt;mx:Button label=&quot;Submit&quot; click=&quot;hello();&quot;/&gt;

    &lt;/mx:Panel&gt;
&lt;/mx:Application&gt;</pre>
<p>&nbsp;
<object height="200" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="300">
<param name="src" value="http://livedocs.adobe.com/flex/3/html/movies/TriggerCodeExample2.swf" />
<embed src="http://livedocs.adobe.com/flex/3/html/movies/TriggerCodeExample2.swf" type="application/x-shockwave-flash" height="200" width="300"></embed>
</object>
</p>
<h2 class="h2nobreak">Binding data between components</h2>
<p>组件中的数据绑定</p>
<p>Flex provides simple syntax for binding the properties of components to
each other. In the following example, the value inside the curly braces
({ }) binds the <samp class="codeph">text</samp>
 property of a <a href="http://livedocs.adobe.com/flex/3/langref/mx/controls/TextArea.html" target="_blank">TextArea</a>
 control to the <samp class="codeph">text</samp>
 property of a TextInput control. When the application initializes, both controls display the text <samp class="codeph">Hello</samp>
. When the user clicks the <a href="http://livedocs.adobe.com/flex/3/langref/mx/controls/Button.html" target="_blank">Button</a>
 control, both controls display the text <samp class="codeph">Goodbye</samp>
.</p>
<p>Flex提供了一套简单语法用来将组件间的属性进行绑定。下面的例子中，在{}中的值将一个TexaArea的text属性与一个TextInput的text属性相绑定。当应用初始化时，两个组件都会显示Hello。当用户点击Button时，两个组件会同时显示Goodbye.</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!-- mxml/BindingExample.mxml --&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
    &lt;mx:Panel title=&quot;My Application&quot; 
        paddingTop=&quot;10&quot; 
        paddingBottom=&quot;10&quot;
        paddingLeft=&quot;10&quot; 
        paddingRight=&quot;10&quot;
    &gt;
        &lt;mx:TextInput id=&quot;textinput1&quot; text=&quot;Hello&quot;/&gt;
        &lt;mx:TextArea id=&quot;textarea1&quot; text=&quot;{textinput1.text}&quot;/&gt;
        &lt;mx:Button label=&quot;Submit&quot; click=&quot;textinput1.text='Goodbye';&quot;/&gt;
    &lt;/mx:Panel&gt;
&lt;/mx:Application&gt;</pre>
<p>&nbsp;
<object height="200" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="400">
<param name="src" value="http://livedocs.adobe.com/flex/3/html/movies/BindingExample.swf" />
<embed src="http://livedocs.adobe.com/flex/3/html/movies/BindingExample.swf" type="application/x-shockwave-flash" height="200" width="400"></embed>
</object>
</p>
<p>As an alternative to the curly braces ({ }) syntax, you can use the <samp class="codeph">&lt;mx:Binding&gt;</samp>
tag, in which you specify the source and destination of a binding. </p>
<p>与{}有相同功效的是&lt;mx:Binding&gt;标签，你可指定源和目的进行数据绑定。</p>
<h2 class="h2nobreak">Using RPC services</h2>
<p>使用RPC服务</p>
<p>Remote-procedure-call (RPC) services let your application interact
with remote servers to provide data to your applications, or for your
application to send data to a server.</p>
<p>远程方法调用(RPC)服务可以让你的应用与远程服务器通信并获得数据，或者向远程服务器发送数据。</p>
<p>Flex is designed to
interact with several types of RPC services that provide access to
local and remote server-side logic. For example, a Flex application can
connect to a web service that uses the Simple Object Access Protocol
(SOAP), a Java object residing on the same application server as Flex
using AMF, or an HTTP URL that returns XML.</p>
<p>Flex设计了几种与本地和远程服务器通信的RPC服务方式。例如，一个Flex应用可以通过SOAP协议进行web service通信，并返回AMF(Action Message Format)对象，或者是一个HTTP请求，返回XML数据。</p>
<p>The MXML components that provide data access are called RPC components. MXML includes the following types of RPC components:</p>
<p>提供数据访问的MXML组件叫做RPC组件。MXML包括以下RPC组件：</p>
<ul>
<li><a href="http://livedocs.adobe.com/flex/3/langref/mx/rpc/soap/mxml/WebService.html" target="_blank">WebService</a>
 provides access to SOAP-based web services.
</li>
<li><a href="http://livedocs.adobe.com/flex/3/langref/mx/rpc/http/mxml/HTTPService.html" target="_blank">HTTPService</a>
 provides access to HTTP URLs that return data.
</li>
<li><a href="http://livedocs.adobe.com/flex/3/langref/mx/rpc/remoting/mxml/RemoteObject.html" target="_blank">RemoteObject</a>
 provides access to Java objects using the AMF protocol (Adobe LiveCycle Data Services ES only).</li>
<li>WebService 提供了基于SOAP的web服务</li>
<li>HTTPService提供了通过HTTP URL访问并返回数据的方式</li>
<li>RemoteObject提供了用AMF协议访问Java对象（只适用于Adobe LiveCycle Data Service ES）<br />
</li>
</ul>
<p>The following example shows an application that calls a web service
that provides weather information, and displays the current temperature
for a given ZIP code. The application binds the ZIP code that a user
enters in a TextInput control to a web service input parameter. It
binds the current temperature value contained in the web service result
to a TextArea control.</p>
<p>下面的例子展示的是一个Flex应用通过调用web service获得天气信息并根据给出的地区编码获得当前的温度。应用将TextInput中的地区编码与web service输入参数绑定，并将web service中获得的当前温度值与TexaArea绑定。</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!-- mxml/RPCExample.mxml --&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
    &lt;!-- Define the web service connection
        (the specified WSDL URL is not functional). --&gt;
    &lt;mx:WebService id=&quot;WeatherService&quot;       
        wsdl=&quot;http:/example.com/ws/WeatherService?wsdl&quot; 
        useProxy=&quot;false&quot;&gt;

        &lt;!-- Bind the value of the ZIP code entered in the TextInput control
            to the ZipCode parameter of the GetWeather operation. --&gt;
        &lt;mx:operation name=&quot;GetWeather&quot;&gt;
            &lt;mx:request&gt;
                &lt;ZipCode&gt;{zip.text}&lt;/ZipCode&gt;
            &lt;/mx:request&gt;
        &lt;/mx:operation&gt;
    &lt;/mx:WebService&gt;
    
    &lt;mx:Panel title=&quot;My Application&quot; paddingTop=&quot;10&quot; paddingBottom=&quot;10&quot;
        paddingLeft=&quot;10&quot; paddingRight=&quot;10&quot; &gt;

        &lt;!-- Provide a ZIP code in a TextInput control. --&gt;
        &lt;mx:TextInput id=&quot;zip&quot; width=&quot;200&quot; text=&quot;Zipcode please?&quot;/&gt;

        &lt;!-- Call the web service operation with a Button click. --&gt;
        &lt;mx:Button width=&quot;60&quot; label=&quot;Get Weather&quot;
            click=&quot;WeatherService.GetWeather.send();&quot;/&gt;

        &lt;!-- Display the location for the specified ZIP code. --&gt;
        &lt;mx:Label text=&quot;Location:&quot;/&gt;
        &lt;mx:TextArea text=&quot;{WeatherService.GetWeather.lastResult.Location}&quot;/&gt;

        &lt;!-- Display the current temperature for the specified ZIP code. --&gt;
        &lt;mx:Label text=&quot;Temperature:&quot;/&gt;
        &lt;mx:TextArea
            text=&quot;{WeatherService.GetWeather.lastResult.CurrentTemp}&quot;/&gt;
    &lt;/mx:Panel&gt;
&lt;/mx:Application&gt;</pre>
&nbsp;
<h2 class="h2nobreak">Storing data in a data model</h2>
<p>在数据模型中存储数据</p>
<p>You can use a data model to store application-specific data. A <em>data model </em>
is
an ActionScript object that provides properties for storing data, and
optionally contains methods for additional functionality. Data models
provide a way to store data in the Flex application before it is sent
to the server, or to store data sent from the server before using it in
the application.</p>
<p>你可以用一个数据模型存储应用中的数据。数据模型是一个提供了存储数据的ActionScript对象，并可以增加一些方法对功能进行扩展。数据模型提供了一种将数据发送到服务端前进行存储的方式，或缓存从服务端回来的数据。</p>
<p>You can declare a simple data model that does not require methods in an <samp class="codeph">&lt;mx:Model&gt;</samp>
, <samp class="codeph">&lt;mx:XML&gt;</samp>
, or <samp class="codeph">&lt;mx:XMLList&gt;</samp>
 tag. The following example shows an application that contains <a href="http://livedocs.adobe.com/flex/3/langref/mx/controls/TextInput.html" target="_blank">TextInput</a>
 controls for entering personal contact information and a data model, represented by the <samp class="codeph">&lt;mx:Model&gt;</samp>
 tag, for storing the contact information:</p>
<p>你可以在&lt;mx:Model&gt;,&lt;mx:XML&gt;或&lt;mx:XMLList&gt;中声明一个没有方法的简单数据模型。下面的例子是一个包含了用于输入个人信息的TextInput和一个由&lt;mx:Model&gt;声明的用于存储这些信息的数据模型。</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!-- mxml/StoringData.mxml --&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;

    &lt;!-- A data model called &quot;contact&quot; stores contact information.
        The text property of each TextInput control shown above
        is passed to a field of the data model. --&gt;
    &lt;mx:Model id=&quot;contact&quot;&gt;
        &lt;info&gt;
            &lt;homePhone&gt;{homePhoneInput.text}&lt;/homePhone&gt;
            &lt;cellPhone&gt;{cellPhoneInput.text}&lt;/cellPhone&gt;
            &lt;email&gt;{emailInput.text}&lt;/email&gt;
        &lt;/info&gt;
    &lt;/mx:Model&gt;

    &lt;mx:Panel title=&quot;My Application&quot; paddingTop=&quot;10&quot; paddingBottom=&quot;10&quot;
        paddingLeft=&quot;10&quot; paddingRight=&quot;10&quot; &gt;
        &lt;!-- The user enters contact information in TextInput controls. --&gt;
        &lt;mx:TextInput id=&quot;homePhoneInput&quot;
            text=&quot;This isn't a valid phone number.&quot;/&gt;
        &lt;mx:TextInput id=&quot;cellPhoneInput&quot; text=&quot;(999)999-999&quot;/&gt;
        &lt;mx:TextInput id=&quot;emailInput&quot; text=&quot;me@somewhere.net&quot;/&gt;
    &lt;/mx:Panel&gt;

&lt;/mx:Application&gt;</pre>
<p>&nbsp;
<object height="200" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="300">
<param name="src" value="http://livedocs.adobe.com/flex/3/html/movies/StoringData.swf" />
<embed src="http://livedocs.adobe.com/flex/3/html/movies/StoringData.swf" type="application/x-shockwave-flash" height="200" width="300"></embed>
</object>
</p>
<h2 class="h2nobreak">Validating data</h2>
<p>数据验证</p>
<p>You can use validator components to validate data stored in a data
model, or in a Flex user interface component. Flex includes a set of
standard validator components. You can also create your own.</p>
<p>你可以通过数据验证组件对存储在数据模型或Flex用户接口中的数据进行验证。Flex包含一组标准的数据验证组件。你也可以自定义自己的验证组件。</p>
<p>The following example uses validator components for validating that the expected type of data is entered in the <a href="http://livedocs.adobe.com/flex/3/langref/mx/controls/TextInput.html" target="_blank">TextInput</a>
fields. Validation is triggered automatically when the user edits a
TextInput control. If validation fails, the user receives immediate
visual feedback.</p>
<p>下面的例子是一个通过数据验证组件验证输入到TextInput中数据。当用户对一个TextInput进行编辑操作时，验证会自动触发。如果验证失败，用户可以立刻看到相关的错误提示信息。</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!-- mxml/ValidatingExample.mxml --&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
    &lt;!-- A data model called &quot;contact&quot; stores contact information.
        The text property of each TextInput control shown above
        is passed to a field of the data model. --&gt;
    &lt;mx:Model id=&quot;contact&quot;&gt;
        &lt;info&gt;
            &lt;homePhone&gt;{homePhoneInput.text}&lt;/homePhone&gt;
            &lt;cellPhone&gt;{cellPhoneInput.text}&lt;/cellPhone&gt;
            &lt;email&gt;{emailInput.text}&lt;/email&gt;
        &lt;/info&gt;
    &lt;/mx:Model&gt;

    &lt;!-- Validator components validate data entered into the TextInput controls. --&gt;
    &lt;mx:PhoneNumberValidator id=&quot;pnV&quot; 
        source=&quot;{homePhoneInput}&quot; property=&quot;text&quot;/&gt;
    &lt;mx:PhoneNumberValidator id=&quot;pnV2&quot; 
        source=&quot;{cellPhoneInput}&quot; property=&quot;text&quot;/&gt;
    &lt;mx:EmailValidator id=&quot;emV&quot; source=&quot;{emailInput}&quot; property=&quot;text&quot; /&gt;

    &lt;mx:Panel title=&quot;My Application&quot; paddingTop=&quot;10&quot; paddingBottom=&quot;10&quot;
        paddingLeft=&quot;10&quot; paddingRight=&quot;10&quot; &gt;
        &lt;!-- The user enters contact information in TextInput controls. --&gt;
        &lt;mx:TextInput id=&quot;homePhoneInput&quot;
            text=&quot;This isn't a valid phone number.&quot;/&gt;
        &lt;mx:TextInput id=&quot;cellPhoneInput&quot; text=&quot;(999)999-999&quot;/&gt;
        &lt;mx:TextInput id=&quot;emailInput&quot; text=&quot;me@somewhere.net&quot;/&gt;
    &lt;/mx:Panel&gt;

&lt;/mx:Application&gt;</pre>
<p>&nbsp;
<object height="200" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="300">
<param name="src" value="http://livedocs.adobe.com/flex/3/html/movies/ValidatingExample.swf" />
<embed src="http://livedocs.adobe.com/flex/3/html/movies/ValidatingExample.swf" type="application/x-shockwave-flash" height="200" width="300"></embed>
</object>
</p>
<h2 class="h2nobreak">Formatting data</h2>
<p>数据格式化</p>
<p>Formatter components are ActionScript components that perform a one-way
conversion of raw data to a formatted string. They are triggered just
before data is displayed in a text field. Flex includes a set of
standard formatters. You can also create your own formatters. The
following example shows an application that uses the standard <a href="http://livedocs.adobe.com/flex/3/langref/mx/formatters/ZipCodeFormatter.html" target="_blank">ZipCodeFormatter</a>
 component to format the value of a variable:</p>
<p>格式化组件是一组ActionScript组件，它提供一种将原始数据格式化的方式。它们只会在在数据显示在文本区域后触发。Flex包含了一组标准的格式化组件。你也可以创建自己的格式化组件。下面是一个使用标准的格式化组件ZipCodeFormatter对数据进行格式化的例子。</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!-- mxml/FormatterExample.mxml --&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;

    &lt;!-- Declare a ZipCodeFormatter and define parameters. --&gt;
    &lt;mx:ZipCodeFormatter id=&quot;ZipCodeDisplay&quot; formatString=&quot;#####-####&quot;/&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            [Bindable]
            private var storedZipCode:Number=123456789;
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Panel title=&quot;My Application&quot; 
        paddingTop=&quot;10&quot; 
        paddingBottom=&quot;10&quot;
        paddingLeft=&quot;10&quot; 
        paddingRight=&quot;10&quot;
    &gt;
        &lt;!-- Trigger the formatter while populating a string with data. --&gt;
        &lt;mx:TextInput text=&quot;{ZipCodeDisplay.format(storedZipCode)}&quot;/&gt; 
    &lt;/mx:Panel&gt;
&lt;/mx:Application&gt;</pre>
<p>&nbsp;
<object height="200" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="300">
<param name="src" value="http://livedocs.adobe.com/flex/3/html/movies/FormatterExample.swf" />
<embed src="http://livedocs.adobe.com/flex/3/html/movies/FormatterExample.swf" type="application/x-shockwave-flash" height="200" width="300"></embed>
</object>
</p>
<h2 class="h2nobreak">Using Cascading Style Sheets (CSS)</h2>
<p>使用CSS</p>
<p>You can use style sheets based on the CSS standard to declare styles to Flex components. The MXML <samp class="codeph">&lt;mx:Style&gt;</samp>
tag contains inline style definitions or a reference to an external file that contains style definitions.</p>
<p>你可以使用基于标准CSS的样式表对Flex组件进行定义。&lt;mx:Sytle&gt;标签包含了内嵌的样式定义或一个指向外部样式定义文件的引用。</p>
<p>The <samp class="codeph">&lt;mx:Style&gt;</samp>
tag must be an immediate child of the root tag of the MXML file. You
can apply styles to an individual component using a class selector, or
to all components of a certain type using a type selector.</p>
<p>&lt;mx:Style&gt;标签必须是MXML文件跟标签的直接子标签。你可以通过一个类选择器将样式应用于单独的组件，或所有的组件。</p>
<p>The following example defines a class selector and a type selector in the <samp class="codeph">&lt;mx:Style&gt;</samp>
 tag. Both the class selector and the type selector are applied to the Button control.</p>
<p>下面的例子在&lt;mx:Style&gt;中定义了一个类选择权和一个样式选择器。两个选择器都应用于Button控件上。</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!-- mxml/CSSExample.mxml --&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
    &lt;mx:Style&gt;
        .myClass { color: Red } /* class selector */
        Button { font-size: 18pt} /* type selector */
    &lt;/mx:Style&gt;

    &lt;mx:Panel title=&quot;My Application&quot; 
        paddingTop=&quot;10&quot; 
        paddingBottom=&quot;10&quot;
        paddingLeft=&quot;10&quot; 
        paddingRight=&quot;10&quot;
    &gt;
        &lt;mx:Button styleName=&quot;myClass&quot; label=&quot;This is red 18 point text.&quot;/&gt;
    &lt;/mx:Panel&gt;
&lt;/mx:Application&gt;</pre>
<p>&nbsp;
<object height="200" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="400">
<param name="src" value="http://livedocs.adobe.com/flex/3/html/movies/CSSExample.swf" />
<embed src="http://livedocs.adobe.com/flex/3/html/movies/CSSExample.swf" type="application/x-shockwave-flash" height="200" width="400"></embed>
</object>
</p>
<h2 class="h2nobreak">Using skins</h2>
<h2 class="h2nobreak">使用皮肤<br />
</h2>
<p><em>Skinning</em>
 is the process of changing the appearance of a
component by modifying or replacing its visual elements. These elements
can be made up of bitmap images, SWF files, or class files that contain
drawing methods that define vector images. Skins can define the entire
appearance, or only a part of the appearance, of a component in various
states. </p>
<p>换肤是通过改变或替换组件的可视化原始进而改变组件样式的过程。这些元素可以是位图、SWF文件或包含绘图方法的类文件。通过换肤可以定义组件的全部或一部分表现。</p>
<h2 class="h2nobreak">Using effects</h2>
<h2 class="h2nobreak">使用效果组件<br />
</h2>
<p>An <em>effect</em>
 is a change to a component that occurs over a brief
period of time. Examples of effects are fading, resizing, and moving a
component. An effect is combined with a <em>trigger</em>
, such as a mouse click on a component, a component getting focus, or a component becoming visible, to form a <em>behavior</em>
.
In MXML, you apply effects as properties of a control or container.
Flex provides a set of built-in effects with default properties.</p>
<p>所谓效果是指在一段很短的时间内组件发生的一些变化。效果的一些例子如褪色、尺寸变换、组件移动等。一个效果会与一个触发器相结合，就像用鼠标点击一个组件，组件获得焦点或组件可视等一些行为。在MXML中，你可将效果作为组件或容器的属性使用。Flex定义了一些默认的内置效果。</p>
<p>The following example shows an application that contains a <a href="http://livedocs.adobe.com/flex/3/langref/mx/controls/Button.html" target="_blank">Button</a>
 control with its <samp class="codeph">rollOverEffect</samp>
 property set to use the <a href="http://livedocs.adobe.com/flex/3/langref/mx/effects/WipeLeft.html" target="_blank">WipeLeft</a>
 effect when the user moves the mouse over it:</p>
<p><samp class="codeph"></samp>
</p>
<p>下面的例子是一个包含了rollOverEffect属性的button控件，当鼠标在控件上时，WipeLeft效果会被触发。</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!-- mxml/WipeLeftEffect.mxml --&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
    &lt;!-- Define the effect. --&gt;
    &lt;mx:WipeLeft id=&quot;myWL&quot; duration=&quot;1000&quot;/&gt;

    &lt;mx:Panel title=&quot;My Application&quot; 
        paddingTop=&quot;10&quot; 
        paddingBottom=&quot;10&quot;
        paddingLeft=&quot;10&quot; 
        paddingRight=&quot;10&quot;
    &gt;
        &lt;!-- Assign effect to targets. --&gt;
        &lt;mx:Button id=&quot;myButton&quot; rollOverEffect=&quot;{myWL}&quot;/&gt;
    &lt;/mx:Panel&gt;
&lt;/mx:Application&gt;</pre>
<p>
<object height="200" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="300">
<param name="src" value="http://livedocs.adobe.com/flex/3/html/movies/WipeLeftEffect.swf" />
<embed src="http://livedocs.adobe.com/flex/3/html/movies/WipeLeftEffect.swf" type="application/x-shockwave-flash" height="200" width="300"></embed>
</object>
</p>
<h2 class="h2nobreak">Defining custom MXML components</h2>
<h2 class="h2nobreak">定义自定义MXML组件<br />
</h2>
<p>Custom MXML components are MXML files that you create and use as
custom MXML tags in other MXML files. They encapsulate and extend the
functionality of existing Flex components. Just like MXML application
files, MXML component files can contain a mix of MXML tags and
ActionScript code. The name of the MXML file becomes the class name
with which you refer to the component in another MXML file.</p>
<p>自定义MXML组件是你自己创建的MXML标签。它们继承已存在的Flex组件。就像MXML应用程序文件，MXML组件文件可以包含MXML标签和ActionScript代码。MXML文件的名字就是你在其他MXML文件中使用这个组件的类名。</p>
<p>The following example shows a custom <a href="http://livedocs.adobe.com/flex/3/langref/mx/controls/ComboBox.html" target="_blank">ComboBox</a>
 control that is prepopulated with list items:</p>
<p>下面的例子是一个自定义ComboBox组件：</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!-- mxml/containers/boxes/MyComboBox.mxml --&gt;
&lt;mx:VBox xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
     &lt;mx:ComboBox &gt;
        &lt;mx:dataProvider&gt;
            &lt;mx:String&gt;Dogs&lt;/mx:String&gt;
            &lt;mx:String&gt;Cats&lt;/mx:String&gt;
            &lt;mx:String&gt;Mice&lt;/mx:String&gt;
        &lt;/mx:dataProvider&gt;
    &lt;/mx:ComboBox&gt;
&lt;/mx:VBox&gt;</pre>
<p>The following example shows an application that uses the MyComboBox component as a custom tag. The value <samp class="codeph">containers.boxes.*</samp>
 assigns the <samp class="codeph">MyComps</samp>
namespace to the containers/boxes sub-directory. To run this example, store the MyComboBox.mxml file in that sub-directory.</p>
<p>下面的例子是一个应用使用MyComboBox自定义组件。containers.boxes.*指定了MyComps命名空间为containers/boxes子路径。运行这个例子需要将MyComboBox.mxml放在那个路径下。</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!-- mxml/CustomMXMLComponent.mxml --&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; xmlns:MyComps=&quot;containers.boxes.*&quot;&gt;

    &lt;mx:Panel title=&quot;My Application&quot; 
        paddingTop=&quot;10&quot; 
        paddingBottom=&quot;10&quot;
        paddingLeft=&quot;10&quot; 
        paddingRight=&quot;10&quot; 
    &gt;
        &lt;MyComps:MyComboBox/&gt;
    &lt;/mx:Panel&gt;
&lt;/mx:Application&gt;</pre>
<p>&nbsp;
<object height="200" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="300">
<param name="src" value="http://livedocs.adobe.com/flex/3/html/movies/CustomMXMLComponent.swf" />
<embed src="http://livedocs.adobe.com/flex/3/html/movies/CustomMXMLComponent.swf" type="application/x-shockwave-flash" height="200" width="300"></embed>
</object>
</p>
<p>&nbsp;</p>
          <br/>
          <span style="color:red;">
            <a href="http://tangshuo.javaeye.com/blog/188322#comments" style="color:red;">本文的讨论也很精彩，浏览讨论>></a>
          </span>
          <br/><br/><br/>
          <span style="color:#E28822;">JavaEye推荐</span>
          <br/>
          <ul class='adverts'><li><a href='/adverts/41' target='_blank'><span style="color:red;font-weight:bold;">北京: 千橡集团暨校内网诚聘软件研发工程师</span></a></li><li><a href='/adverts/42' target='_blank'><span style="color:red;font-weight:bold;">搜狐网站诚聘Java、PHP和C++工程师</span></a></li></ul>
          <br/><br/><br/>
          ]]>
        </description>
        <pubDate>Wed, 30 Apr 2008 10:55:28 +0800</pubDate>
        <link>http://tangshuo.javaeye.com/blog/188322</link>
        <guid>http://tangshuo.javaeye.com/blog/188322</guid>
      </item>
      <item>
        <title>从服务器端获得数据并用Flex展示</title>
        <author>tangshuo</author>
        <description>
          <![CDATA[
          <br/>
          作者: <a href="http://tangshuo.javaeye.com">tangshuo</a>&nbsp;
          链接：<a href="http://tangshuo.javaeye.com/blog/187930" style="color:red;">http://tangshuo.javaeye.com/blog/187930</a>&nbsp;
          发表时间: 2008年04月29日
          <br/><br/>
          声明：本文系JavaEye网站发布的原创博客文章，未经作者书面许可，严禁任何网站转载本文，否则必将追究法律责任！
          <br/><br/>
          <p> &nbsp;&nbsp; &nbsp;&nbsp; 如何从服务器端获得数据并通过Flex以图表形式展现出来，主要思路是：用户通过浏览器调用嵌入Flex应用的html页面-&gt;Flex应用发送请求到服务端请求数据-&gt;服务端将数据返回给Flex应用-&gt;Flex向用户展示数据。 下面分别从服务端和Flex进行说明：</p>
<p>1.编写服务端</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;  服务端用来向Flex应用返回请求的数据。这里的数据格式设置为XML数据。对于XML数据，可以直接返回一个XML文件或者通过编码返回XML格式的数据。这里我们采用后者，这里的服务端还接收一个参数：type，根据type不同返回不同的XML数据。</p>
<pre name="code" class="java">package service;

import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

/**
 * 返回Flex请求的XML数据
 * @author tangs
 */
public class DataServiceServlet extends HttpServlet {
   
    /** 
    * Processes requests for both HTTP &lt;code&gt;GET&lt;/code&gt; and &lt;code&gt;POST&lt;/code&gt; methods.
    * @param request servlet request
    * @param response servlet response
    */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType(&quot;text/xml;charset=UTF-8&quot;);
        PrintWriter out = response.getWriter();
        try {
            //根据type不同，返回不同的XML数据
            String type = request.getParameter(&quot;type&quot;);
            
            StringBuilder xml = new StringBuilder();
            xml.append(&quot;&lt;?xml version='1.0' encoding='UTF-8'?&gt;&quot;);
            if (&quot;1&quot;.equals(type)) {
                xml.append(&quot;&lt;root&gt;&quot;);
                xml.append(&quot;&lt;Expense name='Taxses' value='3000'/&gt;&quot;);
     		xml.append(&quot;&lt;Expense name='Rent' value='1520'/&gt;&quot;);
                xml.append(&quot;&lt;Expense name='Bills' value='500'/&gt;&quot;);        
                xml.append(&quot;&lt;/root&gt;&quot;);
            } else if (&quot;2&quot;.equals(type)) {
                xml.append(&quot;&lt;root&gt;&quot;);
                xml.append(&quot;&lt;Expense name='Taxses' value='5000'/&gt;&quot;);
     		xml.append(&quot;&lt;Expense name='Rent' value='1020'/&gt;&quot;);
                xml.append(&quot;&lt;Expense name='Bills' value='210'/&gt;&quot;);        
                xml.append(&quot;&lt;/root&gt;&quot;);
            }
            out.println(xml.toString());
        } finally { 
            out.close();
        }
    } 

    // &lt;editor-fold defaultstate=&quot;collapsed&quot; desc=&quot;HttpServlet methods. Click on the + sign on the left to edit the code.&quot;&gt;
    /** 
    * Handles the HTTP &lt;code&gt;GET&lt;/code&gt; method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
    * Handles the HTTP &lt;code&gt;POST&lt;/code&gt; method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
    * Returns a short description of the servlet.
    */
    public String getServletInfo() {
        return &quot;Short description&quot;;
    }
    // &lt;/editor-fold&gt;
}</pre>
<p>&nbsp;服务端很简单，就是返回请求数据。</p>
<p>2.编写Flex应用</p>
<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;  这个例子总Flex需要向服务端发送请求的同时，传递一个参数。用Flex发送带参数请求很简单，但是如何向Flex应用传递参数，却有些繁琐。下面先来看Flex应用如何获得外部传来的参数：</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!-- charts/BasicPie.mxml --&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; 
    initialize=&quot;getParams();&quot;&gt;    //Flex应用初始化时，向服务端获取数据
  &lt;mx:Script&gt;&lt;![CDATA[
     import mx.collections.ArrayCollection;
	 import mx.rpc.http.HTTPService;
	 import mx.controls.Alert;
	 
	 [Bindable]
	 private var service:HTTPService ;
		
	 private function get_Label(item:Object, field:String, index:Number, percentValue:Number):String
	 {
		 return item[&quot;name&quot;].toString()+&quot;:&quot;+item[field].toString();
	 }
		
	 //获得参数
	 private function getParams():void {
	 	 //获得参数
	 	 var params:Object = this.parameters;
		 if (params != null) {
				//向服务端请求数据
				service = DataLoader.getData(params[&quot;type&quot;].toString());
		 } else {
				Alert.show(&quot;No params&quot;);
		 }
			
	 }
		
		
  ]]&gt;&lt;/mx:Script&gt;

  &lt;mx:Panel title=&quot;Pie Chart&quot; backgroundColor=&quot;#FFFFFF&quot;&gt;
    //展示饼状图
     &lt;mx:PieChart id=&quot;myChart&quot; 
        dataProvider=&quot;{service.lastResult.root.Expense}&quot;    //获得服务端返回的数据
        showDataTips=&quot;true&quot;
     &gt;
        &lt;mx:series&gt;
           &lt;mx:PieSeries 
                field=&quot;value&quot; 
                nameField=&quot;name&quot; 
                labelPosition=&quot;callout&quot;
                labelFunction=&quot;get_Label&quot;
           /&gt;
        &lt;/mx:series&gt;
     &lt;/mx:PieChart&gt;
     &lt;mx:Legend dataProvider=&quot;{myChart}&quot;/&gt;
  &lt;/mx:Panel&gt;
&lt;/mx:Application&gt;</pre>
<p>&nbsp;从上面的代码可以看出，Flex获得参数的方法：</p>
<pre name="code" class="java">	 private function getParams():void {
	 	 //获得参数
	 	 <span style="color: #ff0000;">var params:Object = this.parameters;</span>


		 if (params != null) {
				//向服务端请求数据
				service = DataLoader.getData(<span style="color: #ff0000;">params[&quot;type&quot;].toString()</span>

);
		 } else {
				Alert.show(&quot;No params&quot;);
		 }
			
	 }

</pre>
<p>&nbsp;在应用加载的时候，通过调用getParams()方法，获得传入的参数，并向服务端请求数据。</p>
<p>&nbsp;Flex向服务端请求数据有3种方式：REST-sytle service，web service，Remote object service。这里使用的是第一种方式。REST-style service实际上就是采用HTTP协议通信的方式。Flex提供了HTTPService component，使用起来很方便。这里用的是ActionScript：</p>
<p>&nbsp; DataLoader.as</p>
<pre name="code" class="java">package
{
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;

	public class DataLoader
	{
		
		public function DataLoader()
		{
		}
		public static function getData(type:Object):HTTPService {
				var service:HTTPService;
                service = new HTTPService();
                service.url = &quot;http://localhost:7001/DataService/getData?type=&quot;+type;
                service.method = &quot;POST&quot;;
                service.addEventListener(&quot;result&quot;, httpResult);
                service.addEventListener(&quot;fault&quot;, httpFault);
                service.send();
                
                return service;
        }

        public static function httpResult(event:ResultEvent):void {
                var result:Object = event.result;
        }

        public static function httpFault(event:FaultEvent):void {
                var faultstring:String = event.fault.faultString;
                Alert.show(&quot;Fault: &quot; + faultstring);
        }
}</pre>
&nbsp;
<p>&nbsp;下面的代码得到服务端返回的数据：</p>
<pre name="code" class="xml">&lt;mx:PieChart id=&quot;myChart&quot; 
        dataProvider=&quot;<span style="color: #ff0000;">{service.lastResult.root.Expense}</span>

&quot;    //获得服务端返回的数据
        showDataTips=&quot;true&quot;
     &gt;
  。。。
&lt;/mx:PieChart&gt;
</pre>
<p>之后，Flex就可以根据获得的数据将图展现出来了。</p>
<p>上面说了Flex如何获得参数并向服务端发送请求，那么参数是如何传递给Flex应用的呢？这里就有点复杂了。需要写一段JS脚本进行参数的传递。</p>
<p>&nbsp; &nbsp; chartType.js</p>
<pre name="code" class="js">var requiredMajorVersion = 9;
var requiredMinorVersion = 0;
var requiredRevision = 0;

&lt;!-- 动态创建Flash --&gt;
&lt;!-- id:应用编号 --&gt;
&lt;!-- url:嵌入网页的SWF文件名称 --&gt;
&lt;!-- width:应用在网页中的宽度 --&gt;
&lt;!-- high:应用在网页中的高度 --&gt;
&lt;!-- type:服务端需要的参数 --&gt;

function sendParameters(id, url, width, high, type)
{
	var hasProductInstall = DetectFlashVer(6, 0, 65);
	var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

	if(hasProductInstall &amp;&amp; !hasRequestedVersion)
	{
		var MMPlayerType = (isIE == true) ? &quot;ActiveX&quot; : &quot;PlugIn&quot;;
		var MMredirectURL = window.location;
    	document.title = document.title.slice(0, 47) + &quot; - Flash Player Installation&quot;;
	    var MMdoctitle = document.title;

		<span style="color: #ff0000;">AC_FL_RunContent</span>

(
			&quot;id&quot;, id,
			&quot;src&quot;, &quot;playerProductInstall&quot;,
			&quot;name&quot;, url,
			&quot;width&quot;, width,
			&quot;height&quot;, high,
			&quot;menu&quot;, false,
			&quot;wmode&quot;, &quot;opaque&quot;,
			&quot;align&quot;, &quot;middle&quot;,
			&quot;quality&quot;, &quot;high&quot;,
			&quot;bgcolor&quot;, &quot;#808080&quot;,
			&quot;allowScriptAccess&quot;,&quot;always&quot;,
			&quot;FlashVars&quot;, &quot;MMredirectURL=&quot;+MMredirectURL+'&amp;MMplayerType='+MMPlayerType+'&amp;MMdoctitle='+MMdoctitle+&quot;&quot;,
			&quot;type&quot;, &quot;application/x-shockwave-flash&quot;,
			&quot;pluginspage&quot;, &quot;http://www.adobe.com/go/getflashplayer&quot;);
	}
	else if(hasRequestedVersion)
	{
		var flashvars = &quot;type=&quot; + type;
		
		<span style="color: #ff0000;">AC_FL_RunContent</span>

(
			&quot;id&quot;, id,
			&quot;src&quot;, url,
			&quot;name&quot;, url,
			&quot;flashvars&quot;, flashvars,
			&quot;menu&quot;, false,
			&quot;width&quot;, width,
			&quot;height&quot;, high,
			&quot;wmode&quot;, &quot;opaque&quot;,
			&quot;align&quot;, &quot;middle&quot;,
			&quot;quality&quot;, &quot;high&quot;,
			&quot;bgcolor&quot;, &quot;#808080&quot;,
			&quot;allowScriptAccess&quot;,&quot;always&quot;,
			&quot;type&quot;, &quot;application/x-shockwave-flash&quot;,
			&quot;pluginspage&quot;, &quot;http://www.adobe.com/go/getflashplayer&quot;);
	}
	else
	{
    	var alternateContent = 'Alternate HTML content should be placed here. '
	  		+ 'This content requires the Adobe Flash Player. '
	   		+ '&lt;a href=http://www.adobe.com/go/getflash/&gt;Get Flash&lt;/a&gt;';
	    document.write(alternateContent);  // insert non-flash content
	}
}

function getInfoForFlash(type)
{    
	if(type.toLowerCase().indexOf(&quot;f_code&quot;) != -1)
	{
        var target = document.getElementById(&quot;f_code&quot;);
        if(target != null)
        	return target.value;
        else
		    return &quot;g01&quot;;
	}
	else if(type.toLowerCase().indexOf(&quot;f_title&quot;) != -1)
    {
        var target = document.getElementById(&quot;f_title&quot;);
        if(target != null)
        	return target.value;
        else
		    return &quot;unkown&quot;;
	}
	else
		return &quot;unkown&quot;;
}</pre>
<p>&nbsp;上面的脚本中，调用了AC_FL_RunContent方法，这个方法是Flex提供给我们的一个方法，用FlexBuilder创建一个Flex Project后，就可以在html-template这个文件夹中看到一个叫AC_OETags.js的文件。这个方法就在这个文件中。下面是调用Flex应用的html页面：</p>
<p>&nbsp;&nbsp; chart.html</p>
<pre name="code" class="html">&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;&lt;/title&gt;
&lt;script src=&quot;AC_OETags.js&quot; language=&quot;javascript&quot;&gt;&lt;/script&gt;

&lt;/head&gt;
&lt;body bgcolor=&quot;#EBEAE5&quot; leftmargin=&quot;0&quot; topmargin=&quot;0&quot;&gt;
&lt;script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot; src=&quot;history.js&quot;&gt;&lt;/script&gt;
&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot; src=&quot;chartType.js&quot;&gt;&lt;/script&gt;
&lt;table width=&quot;770&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; align=&quot;center&quot;&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td align=&quot;center&quot;&gt;
	&lt;script&gt;
		sendParameters(&quot;Chart1&quot;, &quot;Chart1&quot;, 800, 600, &quot;2&quot;);
	&lt;/script&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>&nbsp;这个HTML页面包含了AC_OETags.js和chartType.js。通过sendParameters方法向Flex应用传递参数，并将应用嵌入网页中显示出来。</p>
<p>OK，上面的工作都做好后，在浏览器中输入http://...../chart.html，就可以看到结果了：</p>
<p>这是type=1时的结果：</p>
<p><img src="http://www.javaeye.com/upload/picture/pic/13127/4b6c19dd-194f-3ea4-99a3-2681f48ceaab.jpg?1209437037" height="523" alt="" width="422" />
</p>
<p>这是type=2时的结果：</p>
<p><img src="http://www.javaeye.com/upload/picture/pic/13125/3366364d-81cf-3f5a-906b-d36fbfd02399.jpg?1209436975" height="521" alt="" width="422" />
</p>
          <br/>
          <span style="color:red;">
            <a href="http://tangshuo.javaeye.com/blog/187930#comments" style="color:red;">本文的讨论也很精彩，浏览讨论>></a>
          </span>
          <br/><br/><br/>
          <span style="color:#E28822;">JavaEye推荐</span>
          <br/>
          <ul class='adverts'><li><a href='/adverts/42' target='_blank'><span style="color:red;font-weight:bold;">搜狐网站诚聘Java、PHP和C++工程师</span></a></li><li><a href='/adverts/41' target='_blank'><span style="color:red;font-weight:bold;">北京: 千橡集团暨校内网诚聘软件研发工程师</span></a></li></ul>
          <br/><br/><br/>
          ]]>
        </description>
        <pubDate>Tue, 29 Apr 2008 10:45:43 +0800</pubDate>
        <link>http://tangshuo.javaeye.com/blog/187930</link>
        <guid>http://tangshuo.javaeye.com/blog/187930</guid>
      </item>
      <item>
        <title>用MXML开发Flex应用－关于MXML</title>
        <author>tangshuo</author>
        <description>
          <![CDATA[
          <br/>
          作者: <a href="http://tangshuo.javaeye.com">tangshuo</a>&nbsp;
          链接：<a href="http://tangshuo.javaeye.com/blog/186498" style="color:red;">http://tangshuo.javaeye.com/blog/186498</a>&nbsp;
          发表时间: 2008年04月24日
          <br/><br/>
          声明：本文系JavaEye网站发布的原创博客文章，未经作者书面许可，严禁任何网站转载本文，否则必将追究法律责任！
          <br/><br/>
          <h1> About MXML</h1>
<p>关于MXML</p>
<p>You use two languages to write Flex applications: MXML and
ActionScript. MXML is an XML markup language that you use to lay out
user interface components. You also use MXML to declaratively define
nonvisual aspects of an application, such as access to data sources on
the server and data bindings between user interface components and data
sources on the server.</p>
<p>你可以用两种方式去编写Flex应用：MXML和ActionScript。MXML是一种用来设计编写用户接口组件的XML标记语言。你也可以用MXML去定义一个应用的非可视部分，比如访问服务器数据源和用户接口组件和服务器数据的绑定。</p>
<p>Like HTML, MXML provides tags that
define user interfaces. MXML will seem very familiar if you have worked
with HTML. However, MXML is more structured than HTML, and it provides
a much richer tag set. For example, MXML includes tags for visual
components such as data grids, trees, tab navigators, accordions, and
menus, as well as nonvisual components that provide web service
connections, data binding, and animation effects. You can also extend
MXML with custom components that you reference as MXML tags.</p>
<p>就像HTML一样，MXML用标签来定义用户接口。如果你用过HTML那么再看MXML会感到很熟悉。不过，MXML比HTML更加结构化，规范化，它提供了很多&ldquo;富标签集&rdquo;。例如，MXML包含了定义可视化组件的标签，如data grids, trees, tab navigators, accordions, and
menus，在非可视化组件方面，包含了web service
connections, data binding, and animation effects。你也可以通过继承MXML组件定义自己的组件标签。</p>
<p>One
of the biggest differences between MXML and HTML is that MXML-defined
applications are compiled into SWF files and rendered by Adobe&reg; Flash&reg;
Player or Adobe&reg; AIR&trade;, which provides a richer and more dynamic user
interface than page-based HTML applications.</p>
<p>MXML与HTML的最大不同之处就是，MXML编写的应用将被编译成SWF文件，并运行在Adobe&reg; Flash&reg;
Player or Adobe&reg; AIR&trade;上面，它提供了比基于页面的HTML应用更丰富的表现。</p>
<p>You can write an
MXML application in a single file or in multiple files. MXML also
supports custom components written in MXML and ActionScript files.</p>
<p>你可以将一个MXML应用用一个文件或多个文件编写。MXML同样支持用MXML或ActionScript编写的自定义组件。</p>
<h2 class="h2nobreak">Writing a simple application</h2>
<h2 class="h2nobreak">一个简单的应用<br />
</h2>
<p>Because MXML files are ordinary XML files, you have a wide choice of
development environments. You can write MXML code in a simple text
editor, a dedicated XML editor, or an integrated development
environment (IDE) that supports text editing. Flex supplies a dedicated
IDE, called Adobe&reg; Flex&reg; Builder&trade;, that you can use to develop your
applications.</p>
<p>由于MXML就是一个普通的XML，因此，你有多种开发方式可以选用。你可以在一个简单的文本编辑器里编写MXML代码，或一个专用的XML文件编辑器，或者用一个IDE进行开发。Flex提供了一个专用的Flex开发IDE：Adobe&reg; Flex&reg; Builder&trade;，你可以用它来开发Flex应用。</p>
<p>The following example shows a simple &quot;Hello World&quot; application that contains just an <samp class="codeph">&lt;mx:Application&gt;</samp>
 tag and two child tags, the <samp class="codeph">&lt;mx:Panel&gt;</samp>
 tag and the <samp class="codeph">&lt;mx:Label&gt;</samp>
 tag. The <samp class="codeph">&lt;mx:Application&gt;</samp>
 tag defines the <a href="http://livedocs.adobe.com/flex/3/langref/mx/core/Application.html" target="_blank">Application</a>
 container that is always the root tag of a Flex application. The <samp class="codeph">&lt;mx:Panel&gt;</samp>
 tag defines a <a href="http://livedocs.adobe.com/flex/3/langref/mx/containers/Panel.html" target="_blank">Panel</a>
 container that includes a title bar, a title, a status message, a border, and a content area for its children. The <samp class="codeph">&lt;mx:Label&gt;</samp>
<samp class="codeph"></samp>
tag represents a <a href="http://livedocs.adobe.com/flex/3/langref/mx/controls/Label.html" target="_blank">Label</a>
 control, a very simple user interface component that displays text.</p>
<p>下面是一个非常简单的&quot;Hello World&quot;应用。这个应用只包含了一个&lt;mx:Application&gt;标签和两个子标签：&lt;mx:Panel&gt;和&lt;mx:Label&gt;。&lt;mx:Application&gt;标签用来定义一个应用容器，它一定是一个Flex应用的根标签。&lt;mx:Panel&gt;标签定义了一个版面容器，它里面可以包含一个标题栏，标题，状态栏，边框以及一个内容区域。&lt;mx:Label&gt;标签定义了一个标签控件，用来显示文本信息。</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!-- mxml\HellowWorld.mxml --&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;&gt;
    &lt;mx:Panel title=&quot;My Application&quot; 
        paddingTop=&quot;10&quot; 
        paddingBottom=&quot;10&quot;
        paddingLeft=&quot;10&quot; 
        paddingRight=&quot;10&quot;
    &gt;
        &lt;mx:Label text=&quot;Hello World!&quot; fontWeight=&quot;bold&quot; fontSize=&quot;24&quot;/&gt;
    &lt;/mx:Panel&gt;
&lt;/mx:Application&gt;</pre>
<p>&nbsp;
<object height="200" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="300">
<param name="src" value="http://livedocs.adobe.com/flex/3/html/movies/HelloWorld.swf" />
<embed src="http://livedocs.adobe.com/flex/3/html/movies/HelloWorld.swf" type="application/x-shockwave-flash" height="200" width="300"></embed>
</object>
</p>
<p><strong>About XML encoding</strong>
</p>
<p>关于XML编码</p>
<p>The first line of the document specifies an optional declaration of
the XML version. It is good practice to include encoding information
that specifies how the MXML file is encoded. Many editors let you
select from a range of file encoding options. On North American
operating systems, ISO-8859-1 is the dominant encoding format, and most
programs use that format by default. You can use the UTF-8 encoding
format to ensure maximum platform compatibility. UTF-8 provides a
unique number for every character in a file, and it is platform-,
program-, and language-independent.</p>
<p>上面代码的第一行声明了XML的版本信息。指定MXML文件的编码方式是一个很好的习惯。许多编辑器可以选择不同的编码方式。如果是北美的操作系统，一般是ISO-8859-1编码。你可以用UTF-8编码方式来获得最大限度的平台兼容性。UTF-8编码方式为每个字符提供了独一无二的编码，并且它是与平台、语言无关的。</p>
<p>If you specify an encoding
format, it must match the file encoding you use. The following example
shows an XML declaration tag that specifies the UTF-8 encoding format:</p>
<p>如果你指定了一种编码方式，则它必须符合你这个文件的编码。下面是一个为一个XML文件声明了UTF-8编码方式的例子：</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</pre>
<p>&nbsp;<strong>About the &lt;mx:Application&gt; tag</strong>
</p>
<p>In addition to being the root tag of a Flex application, the&lt;mx:Application&gt;</p>
<samp class="codeph"></samp>
<p>tag represents an <a href="http://livedocs.adobe.com/flex/3/langref/mx/core/Application.html" target="_blank">Application</a>
 container. A <em>container</em>
is a user-interface component that contains other components and has
built-in layout rules for positioning its child components. By default,
an Application container lays out its children vertically from top to
bottom. You can nest other types of containers inside an Application
container, such as the <a href="http://livedocs.adobe.com/flex/3/langref/mx/containers/Panel.html" target="_blank">Panel</a>
 container shown above, to position user interface components according to other rules.</p>
<p>关于&lt;mx:Application&gt;标签</p>
<p>除了作为Flex应用的根标签外，&lt;mx:Application&gt;标签实际上指定了一个应用容器。所谓&ldquo;容器&rdquo;，就是一个用户接口组件，它可以包含其他子组件，并且用一定的规则去安排这些子组件的位置。默认情况下，一个应用容器的将它上面的组件垂直排列，即从上到下。你可以嵌入其他类型的容器，比如上面例子中的面板容器，并可以通过指定排列规则来排列这些组件。</p>
<p><strong>About MXML tag properties</strong>
</p>
<p>关于MXML标签的属性</p>
<p>The properties of an MXML tag, such as the<samp class="codeph">text</samp>
, <samp class="codeph">fontWeight</samp>
, and <samp class="codeph">fontSize</samp>
 properties of the <samp class="codeph">&lt;mx:Label&gt;</samp>
 tag, let you declaratively configure the initial state of the component. You can use ActionScript code in an <samp class="codeph">&lt;mx:Script&gt;</samp>
tag to change the state of a component at run time.</p>
<p>MXML标签的属性，如text,fontWeight,以及&lt;mx:Label&gt;标签的fontSize属性，可以让你直接去配置组件的初始状态。你可以在运行时通过&lt;mx:Script&gt;标签，用ActionScript代码去改变一个组件的状态。</p>
<h2 class="h2nobreak">The relationship of MXML tags to ActionScript classes</h2>
<h2 class="h2nobreak">MXML标签与ActionScript classes的关系<br />
</h2>
<p>Adobe implemented Flex as an ActionScript class library. That class
library contains components (containers and controls), manager classes,
data-service classes, and classes for all other features. You develop
applications by using the MXML and ActionScript languages with the
class library.</p>
<p>Adobe 将Flex封装为一个ActionScript class库。这个类库包含了组件（容器和控制器），管理类，数据服务类以及实现其他特性的类。你通过MXML和ActionScript类库去开发应用程序。</p>
<p>MXML tags correspond to ActionScript classes or
properties of classes. Flex parses MXML tags and compiles a SWF file
that contains the corresponding ActionScript objects. For example, Flex
provides the ActionScript <a href="http://livedocs.adobe.com/flex/3/langref/mx/controls/Button.html" target="_blank">Button</a>
 class that defines the Flex Button control. In MXML, you create a Button control by using the following MXML statement:</p>
<p>MXML标签实际上相当于ActionScript类或类中的属性。Flex将MXML标签解析并编译成一个SWF文件，这个文件包含了与之对应的ActionScript对象。例如，Flex提供了ActionScript Button类来定义Flex Button控制器。在MXML中，你可以通过下面的MXML语句来创建一个Button：</p>
<pre name="code" class="xml">&lt;mx:Button label=&quot;Submit&quot;/&gt;</pre>
<p>When you declare a control using an MXML tag, you create an instance
object of that class. This MXML statement creates a Button object, and
initializes the <samp class="codeph">label</samp>
 property of the Button object to the string <samp class="codeph">&quot;Submit&quot;.</samp>
<samp class="codeph"><br />
</samp>
<samp class="codeph">当你用MXML标签创建一个控制组件时，实际上是创建了一个这个组件的对象。这个MXML语句创建了一个Button对象，并将它的label属性初始化为&quot;Submit&quot;。<br />
</samp>
</p>
<p>An
MXML tag that corresponds to an ActionScript class uses the same naming
conventions as the ActionScript class. Class names begin with an
uppercase letter, and uppercase letters separate the words in class
names. Every MXML tag attribute corresponds to a property of the
ActionScript object, a style applied to the object, or an event
listener for the object. </p>
<p>一个MXML标签就相当于一个与之名称相同的ActionScript类。类目以一个大写字母开头，大写字母用以区分不同的单词。每一个MXML标签的属性相当于ActionScript类的属性，如一个样式属性或一个事件监听器。</p>
<h2 class="h2nobreak">Understanding a Flex application structure</h2>
<h2 class="h2nobreak">理解一个Flex应用的架构<br />
</h2>
<p>You can write an MXML application in a single file or in multiple files. You typically define a main file that contains the <samp class="codeph">&lt;mx:Application&gt;</samp>
tag. From within your main file, you can then reference additional
files written in MXML, ActionScript, or a combination of the two
languages.</p>
<p>你可以在一个或多个文件中编写MXML应用。一般会定义一个主文件，里面包含了&lt;mx:Application&gt;标签。在这个主文件里，可以应用其他MXML文件、ActionScript或两者的结合。</p>
<p>A common coding practice is to divide your Flex
application into functional units, or modules, where each module
performs a discrete task. In Flex, you can divide your application into
separate MXML files and ActionScript files, where each file corresponds
to a different module. By dividing your application into modules, you
provide many benefits, including the following:</p>
<p>一般情况下，一个Flex应用要将不同的功能放到不同的模块中。在Flex中，你可以将你的应用分为MXML文件和ActionScript文件，并且每一个文件都实现了不同的功能。将应用模块化，有以下好处：</p>
<p class="runinhead"><strong>Ease of development&nbsp;</strong>
</p>
<p class="runinhead">利于团队开发</p>
<p class="runinhead">Different developers or development groups can develop and debug modules independently of each other. </p>
<p>不同的开发人员或不同的开发小组可以进行单独的开发或调试。<br /></p>
<p class="runinhead"><strong>Reusability&nbsp;</strong>
</p>
<p class="runinhead">重用性好</p>
<p>You can reuse modules in different applications so that you do not have to duplicate your work.<br />
你可以在不同的应用中重用这些模块，避免了重复开发。</p>
<p class="runinhead"><strong>Maintainability&nbsp;</strong>
</p>
<p class="runinhead">可维护行好</p>
<p class="runinhead">You can isolate and debug errors faster than if your application is developed in a single file. </p>
<p>你可以更快更好的调试程序的错误。<br /></p>
<p>In
Flex, a module corresponds to a custom component implemented either in
MXML or in ActionScript. These custom components can reference other
custom components. There is no restriction on the level of nesting of
component references in Flex. You define your components as required by
your application.</p>
<p>在Flex中，一个模块就是用MXML或ActionScript实现的一个自定义组件。这些自定义组件可以引用其他组件。Flex中没有组件之间相互引用的限制。你可以按需定义你应用程序中的组件。</p>
          <br/>
          <span style="color:red;">
            <a href="http://tangshuo.javaeye.com/blog/186498#comments" style="color:red;">本文的讨论也很精彩，浏览讨论>></a>
          </span>
          <br/><br/><br/>
          <span style="color:#E28822;">JavaEye推荐</span>
          <br/>
          <ul class='adverts'><li><a href='/adverts/42' target='_blank'><span style="color:red;font-weight:bold;">搜狐网站诚聘Java、PHP和C++工程师</span></a></li><li><a href='/adverts/41' target='_blank'><span style="color:red;font-weight:bold;">北京: 千橡集团暨校内网诚聘软件研发工程师</span></a></li></ul>
          <br/><br/><br/>
          ]]>
        </description>
        <pubDate>Thu, 24 Apr 2008 19:11:26 +0800</pubDate>
        <link>http://tangshuo.javaeye.com/blog/186498</link>
        <guid>http://tangshuo.javaeye.com/blog/186498</guid>
      </item>
      <item>
        <title>Hello，Flex！</title>
        <author>tangshuo</author>
        <description>
          <![CDATA[
          <br/>
          作者: <a href="http://tangshuo.javaeye.com">tangshuo</a>&nbsp;
          链接：<a href="http://tangshuo.javaeye.com/blog/186033" style="color:red;">http://tangshuo.javaeye.com/blog/186033</a>&nbsp;
          发表时间: 2008年04月23日
          <br/><br/>
          声明：本文系JavaEye网站发布的原创博客文章，未经作者书面许可，严禁任何网站转载本文，否则必将追究法律责任！
          <br/><br/>
          <p>&nbsp;&nbsp;&nbsp; 刚开始学习Flex，不知从何下手。从以往学习C++，Java的经验来看，任何一门语言都要理论与实践结合。就是找一本书，边看边练，这样学的快。如果有一位前辈教，那就更好了。不过目前看来，只能&ldquo;自学成才&rdquo;了。</p>
<p>&nbsp;&nbsp;&nbsp; Flex相关的书，市面上不是很多，而且质量参差不齐。到dangdang，china-pub上看了看，都没有相中的。突然想起曾经一位高人说过的话：帮助是最好的参考书。就是说，看&ldquo;帮助&rdquo;比看什么书都强。于是乎，找到Flex的在线帮助文档http://livedocs.adobe.com/flex/3/html/index.html，浏览了前几章节，感觉讲的很详细，毕竟是官方的，虽然都是E文，但借着金山词霸的帮助，读下来还是没问题的。ok，就是它了。</p>
<p>&nbsp;&nbsp;&nbsp; 在学习之前，还得找个写代码的工具。对于Flex来说，最好的当然就是Flex Builder了。从Adobe官网下载了最新的Flex3 Builder，http://www.adobe.com/products/flex/，安装好后，就可以开始了。</p>
<p><img src="http://www.javaeye.com/upload/picture/pic/12759/60f0c029-41be-3ae3-b9b4-943295ecfced.jpg?1208943379" height="768" alt="" width="1024" />
</p>
<p><strong>&nbsp;&nbsp;&nbsp; Hello，Flex！</strong>
</p>
<p>&nbsp;&nbsp;&nbsp; 记得以前每看一本语言的基础教程的时候，第一个例子就是经典的&ldquo;Hello, World!&rdquo;。当看到自己的第一个程序在屏幕上打印出&ldquo;Hello，World!&rdquo;的时候，一种小小的成就感油然而生。看来学Flex也得从这下手了。这里，就不Hello World了，来个&ldquo;Hello，Flex!&rdquo;吧。</p>
<p>&nbsp;&nbsp;&nbsp; 1.选择&ldquo;File&rdquo;-&gt;&ldquo;New&rdquo;-&gt;&ldquo;Flex Project&rdquo;</p>
<p><img src="http://www.javaeye.com/upload/picture/pic/12761/27828265-7541-3c54-9d39-17707224b838.jpg?1208943595" height="237" alt="" width="565" />
</p>
<p>2.输入工程名称，指定路径</p>
<p><img src="http://www.javaeye.com/upload/picture/pic/12763/82247f6b-23ef-3427-81b2-1f1258cbf0c1.jpg?1208943736" height="550" alt="" width="742" />
</p>
<p>3.直接点击&ldquo;Finish&rdquo;就可以了。</p>
<p>4.Flex Builder自动生成了HelloFlex.mxml文件，下面就在这个文件中写入代码：</p>
<pre name="code" class="xml">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;

&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;absolute&quot;&gt;

	&lt;mx:Panel title=&quot;Hello Flex&quot; 

        paddingTop=&quot;10&quot; 

        paddingBottom=&quot;10&quot;

        paddingLeft=&quot;10&quot; 

        paddingRight=&quot;10&quot;

    &gt;

        &lt;mx:Label text=&quot;Hello Flex!&quot; fontWeight=&quot;bold&quot; fontSize=&quot;24&quot;/&gt;

    &lt;/mx:Panel&gt;

&lt;/mx:Application&gt;

</pre>
<p>&nbsp;5.右键点击HelloFlex.mxml文件，选择&ldquo;Run Application&rdquo;，就会以网页的形式将结果展现出来</p>
<p><img src="http://www.javaeye.com/upload/picture/pic/12767/02e6c037-dd5e-38c4-963e-226e306ea5c4.jpg?1208946224" height="96" alt="" width="190" />
</p>
<p>哈哈，成了！第一个Flex程序诞生了！感觉还挺简单。至于上面那些代码是什么意思？怎样产生这样的效果。只能往下看才知道了。</p>
          <br/>
          <span style="color:red;">
            <a href="http://tangshuo.javaeye.com/blog/186033#comments" style="color:red;">本文的讨论也很精彩，浏览讨论>></a>
          </span>
          <br/><br/><br/>
          <span style="color:#E28822;">JavaEye推荐</span>
          <br/>
          <ul class='adverts'><li><a href='/adverts/42' target='_blank'><span style="color:red;font-weight:bold;">搜狐网站诚聘Java、PHP和C++工程师</span></a></li><li><a href='/adverts/41' target='_blank'><span style="color:red;font-weight:bold;">北京: 千橡集团暨校内网诚聘软件研发工程师</span></a></li></ul>
          <br/><br/><br/>
          ]]>
        </description>
        <pubDate>Wed, 23 Apr 2008 18:25:41 +0800</pubDate>
        <link>http://tangshuo.javaeye.com/blog/186033</link>
        <guid>http://tangshuo.javaeye.com/blog/186033</guid>
      </item>
      <item>
        <title>大学时做的小游戏，就当作回忆了</title>
        <author>tangshuo</author>
        <description>
          <![CDATA[
          <br/>
          作者: <a href="http://tangshuo.javaeye.com">tangshuo</a>&nbsp;
          链接：<a href="http://tangshuo.javaeye.com/blog/185148" style="color:red;">http://tangshuo.javaeye.com/blog/185148</a>&nbsp;
          发表时间: 2008年04月21日
          <br/><br/>
          声明：本文系JavaEye网站发布的原创博客文章，未经作者书面许可，严禁任何网站转载本文，否则必将追究法律责任！
          <br/><br/>
          <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;上大学时，对游戏非常感兴趣，梦想着以后去做游戏开发，谁知毕业后竟做起了Java。已经好久没有和游戏打交道了，唉，现在看来，只能先拿出来做一个回忆了。说不定以后。。。who knows?</p>
<p>这些都是自己看着书边学边练。</p>
<p><strong>1.QQ连连看。</strong>
</p>
<p>为什么叫&ldquo;QQ连连看&rdquo;？因为上面的图片是QQ头像<img src="../../images/smiles/icon_biggrin.gif" alt="" />
</p>
<p>这是主界面：</p>
<p><img src="../../../upload/picture/pic/12575/5a6ca1d4-c999-37d4-80a1-fa272359b598.jpg" height="640" alt="" width="877" />
</p>
<p><img src="C:\Documents and Settings\tangs\My Documents\My Pictures\QQllk.JPG" alt="" />
</p>
<p>2.光车（Light Car）</p>
<p>这是一个双人游戏。两辆车从主界面的正上方和正下方相对而行，两人分别用键盘控制各自的车。车开过的地方都会形成一条线，谁先撞到车围成的线，谁就输掉了比赛。比赛中会随机产生一些物品，吃掉后会产生加速或减速的效果。</p>
<p>游戏界面：</p>
<p><img src="../../../upload/picture/pic/12573/de2b850a-1ab0-372b-8a0f-dfe72f0ca85e.jpg" height="432" alt="" width="506" />
</p>
<p><img src="C:\Documents and Settings\tangs\My Documents\My Pictures\lightcar.JPG" alt="" />
</p>
<p>3.UFO（一个射击DEMO）</p>
<p>界面上一个飞碟，键盘控制运动和发射导弹。</p>
<p>游戏界面：</p>
<p><img src="C:\Documents and Settings\tangs\My Documents\My Pictures\ufo.JPG" alt="" />
</p>
<p><img src="../../../upload/picture/pic/12577/317910f7-0d2c-3e3b-9a9e-e0dfbfc5ea41.jpg" height="432" alt="" width="506" />
</p>
<p>这是源代码：</p>
<p>&nbsp;</p>
          <br/>
          <span style="color:red;">
            <a href="http://tangshuo.javaeye.com/blog/185148#comments" style="color:red;">本文的讨论也很精彩，浏览讨论>></a>
          </span>
          <br/><br/><br/>
          <span style="color:#E28822;">JavaEye推荐</span>
          <br/>
          <ul class='adverts'><li><a href='/adverts/42' target='_blank'><span style="color:red;font-weight:bold;">搜狐网站诚聘Java、PHP和C++工程师</span></a></li><li><a href='/adverts/41' target='_blank'><span style="color:red;font-weight:bold;">北京: 千橡集团暨校内网诚聘软件研发工程师</span></a></li></ul>
          <br/><br/><br/>
          ]]>
        </description>
        <pubDate>Mon, 21 Apr 2008 19:12:25 +0800</pubDate>
        <link>http://tangshuo.javaeye.com/blog/185148</link>
        <guid>http://tangshuo.javaeye.com/blog/185148</guid>
      </item>
      <item>
        <title>通过WebService上传文件</title>
        <author>tangshuo</author>
        <description>
          <![CDATA[
          <br/>
          作者: <a href="http://tangshuo.javaeye.com">tangshuo</a>&nbsp;
          链接：<a href="http://tangshuo.javaeye.com/blog/184803" style="color:red;">http://tangshuo.javaeye.com/blog/184803</a>&nbsp;
          发表时间: 2008年02月27日
          <br/><br/>
          声明：本文系JavaEye网站发布的原创博客文章，未经作者书面许可，严禁任何网站转载本文，否则必将追究法律责任！
          <br/><br/>
          <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 用WebService传输文件，实际上就是客户端将文件先做成比特流，然后调用webservice接口，服务端再将比特流还原成文件。下面是代码：<br />
服务端：</p>
<div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: #e6e6e6 none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;">
<div><img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" id="_28_651_Open_Image" onclick="this.style.display='none'; document.getElementById('_28_651_Open_Text').style.display='none'; document.getElementById('_28_651_Closed_Image').style.display='inline'; document.getElementById('_28_651_Closed_Text').style.display='inline';" align="top" alt="" />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" id="_28_651_Closed_Image" onclick="this.style.display='none'; document.getElementById('_28_651_Closed_Text').style.display='none'; document.getElementById('_28_651_Open_Image').style.display='inline'; document.getElementById('_28_651_Open_Text').style.display='inline';" align="top" alt="" style="display: none;" />
<span style="color: #0000ff;">public</span>
<span style="color: #000000;">&nbsp;</span>
<span style="color: #0000ff;">class</span>
<span style="color: #000000;">&nbsp;FileTransferWs&nbsp;</span>
<span id="_28_651_Closed_Text" style="border: 1px solid #808080; background-color: #ffffff; display: none;">...</span>
<span id="_28_651_Open_Text"><span style="color: #000000;">{<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" id="_81_649_Open_Image" onclick="this.style.display='none'; document.getElementById('_81_649_Open_Text').style.display='none'; document.getElementById('_81_649_Closed_Image').style.display='inline'; document.getElementById('_81_649_Closed_Text').style.display='inline';" align="top" alt="" />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" id="_81_649_Closed_Image" onclick="this.style.display='none'; document.getElementById('_81_649_Closed_Text').style.display='none'; document.getElementById('_81_649_Open_Image').style.display='inline'; document.getElementById('_81_649_Open_Text').style.display='inline';" align="top" alt="" style="display: none;" />
&nbsp;&nbsp;&nbsp;&nbsp;</span>
<span style="color: #0000ff;">public</span>
<span style="color: #000000;">&nbsp;</span>
<span style="color: #0000ff;">int</span>
<span style="color: #000000;">&nbsp;uploadFile(</span>
<span style="color: #0000ff;">byte</span>
<span style="color: #000000;">&nbsp;[]bs,&nbsp;String&nbsp;fileName)&nbsp;</span>
<span id="_81_649_Closed_Text" style="border: 1px solid #808080; background-color: #ffffff; display: none;">...</span>
<span id="_81_649_Open_Text"><span style="color: #000000;">{<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" alt="" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileOutputStream&nbsp;out&nbsp;</span>
<span style="color: #000000;">=</span>
<span style="color: #000000;">&nbsp;</span>
<span style="color: #0000ff;">null</span>
<span style="color: #000000;">;<br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" id="_120_348_Open_Image" onclick="this.style.display='none'; document.getElementById('_120_348_Open_Text').style.display='none'; document.getElementById('_120_348_Closed_Image').style.display='inline'; document.getElementById('_120_348_Closed_Text').style.display='inline';" align="top" alt="" />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" id="_120_348_Closed_Image" onclick="this.style.display='non