`
jickcai
  • 浏览: 249534 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Flex4实例--FXG and MXML graphics—building a game

    博客分类:
  • flex
XML 
阅读更多

组件:BoardDisplay.mxml
<?xml version="1.0" encoding="utf-8"?>
<Graphic xmlns:fx="http://ns.adobe.com/mxml/2009"
   xmlns="library://ns.adobe.com/flex/spark"
   xmlns:mx="library://ns.adobe.com/flex/mx"
   viewWidth="601" viewHeight="701" click="clickHandler(event)">
<fx:Script>
<![CDATA[
import mx.controls.Alert;

import org.hamcrest.mxml.collection.InArray;
[Bindable]
public var playerOneColor:uint=0xFF0000;
[Bindable]
public var playerTwoColor:uint=0x000000;

private static const EMPTY_COLOR:uint=0xFFFFFF;
[Bindable]
private var _boardData:Array;

[Bindable]
public var playerOneTurn:Boolean=true;

private static const P1:int=1;
private static const P2:int=2;
private static const NONE:int=0;

public function newGame():void
{
playerOneTurn=true;
var boardData:Array=new Array();
for(var row:int=0;row<6;row++){
boardData[row]=[NONE,NONE,NONE,NONE,NONE,NONE];
}
_boardData=boardData;
}

private function getColor(row:int,col:int,board:Array):uint
{
switch(_boardData[row][col])
{
case P1:
return playerOneColor;
case P2:
return playerTwoColor;
default:
return EMPTY_COLOR;
}
}

private function clickHandler(event:MouseEvent):void
{
var column:int=(event.localX-5)/100;
var row:int=getDropRow(column);
if(row==-1){
Alert.show("The column is full.","Illegal Move");
}else{
_boardData[row][column]=playerOneTurn?P1:P2;
playerOneTurn=!playerOneTurn;
_boardData=_boardData.slice(0);
}
}

private function getDropRow(column:int):int
{
for(var i:int=5;i>=0;i--)
{
if(_boardData[i][column]==NONE)
{
return i;
}
}
return -1;
}
]]>
</fx:Script>
<Group>
<Rect x="0" y="0" width="700" height="600">
<fill>
<SolidColor color="#8E6B23"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Rect>
<Ellipse x="5" y="4" width="90" height="90">
<fill>
<SolidColor color="{getColor(0,0,_boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="5" y="4" width="90" height="90">
<fill>
<SolidColor color="{getColor(0, 0, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="5" y="104" width="90" height="90">
<fill>
<SolidColor color="{getColor(1, 0, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="5" y="204" width="90" height="90">
<fill>
<SolidColor color="{getColor(2, 0, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="5" y="304" width="90" height="90">
<fill>
<SolidColor color="{getColor(3, 0, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="5" y="404" width="90" height="90">
<fill>
<SolidColor color="{getColor(4, 0, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="5" y="504" width="90" height="90">
<fill>
<SolidColor color="{getColor(5, 0, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="105" y="4" width="90" height="90">
<fill>
<SolidColor color="{getColor(0, 1, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="105" y="104" width="90" height="90">
<fill>
<SolidColor color="{getColor(1, 1, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="105" y="204" width="90" height="90">
<fill>
<SolidColor color="{getColor(2, 1, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="105" y="304" width="90" height="90">
<fill>
<SolidColor color="{getColor(3, 1, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="105" y="404" width="90" height="90">
<fill>
<SolidColor color="{getColor(4, 1, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="105" y="504" width="90" height="90">
<fill>
<SolidColor color="{getColor(5, 1, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="205" y="4" width="90" height="90">
<fill>
<SolidColor color="{getColor(0, 2, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="205" y="104" width="90" height="90">
<fill>
<SolidColor color="{getColor(1, 2, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="205" y="204" width="90" height="90">
<fill>
<SolidColor color="{getColor(2, 2, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="205" y="304" width="90" height="90">
<fill>
<SolidColor color="{getColor(3, 2, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="205" y="404" width="90" height="90">
<fill>
<SolidColor color="{getColor(4, 2, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="205" y="504" width="90" height="90">
<fill>
<SolidColor color="{getColor(5, 2, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="305" y="5" width="90" height="90">
<fill>
<SolidColor color="{getColor(0, 3, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="305" y="105" width="90" height="90">
<fill>
<SolidColor color="{getColor(1, 3, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="305" y="205" width="90" height="90">
<fill>
<SolidColor color="{getColor(2, 3, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="305" y="305" width="90" height="90">
<fill>
<SolidColor color="{getColor(3, 3, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="305" y="405" width="90" height="90">
<fill>
<SolidColor color="{getColor(4, 3, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="305" y="505" width="90" height="90">
<fill>
<SolidColor color="{getColor(5, 3, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="405" y="5" width="90" height="90">
<fill>
<SolidColor color="{getColor(0, 4, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="405" y="105" width="90" height="90">
<fill>
<SolidColor color="{getColor(1, 4, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="405" y="205" width="90" height="90">
<fill>
<SolidColor color="{getColor(2, 4, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="405" y="305" width="90" height="90">
<fill>
<SolidColor color="{getColor(3, 4, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="405" y="405" width="90" height="90">
<fill>
<SolidColor color="{getColor(4, 4, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="405" y="505" width="90" height="90">
<fill>
<SolidColor color="{getColor(5, 4, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="505" y="5" width="90" height="90">
<fill>
<SolidColor color="{getColor(0, 5, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="505" y="105" width="90" height="90">
<fill>
<SolidColor color="{getColor(1, 5, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="505" y="205" width="90" height="90">
<fill>
<SolidColor color="{getColor(2, 5, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="505" y="305" width="90" height="90">
<fill>
<SolidColor color="{getColor(3, 5, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="505" y="405" width="90" height="90">
<fill>
<SolidColor color="{getColor(4, 5, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="505" y="505" width="90" height="90">
<fill>
<SolidColor color="{getColor(5, 5, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="605" y="5" width="90" height="90">
<fill>
<SolidColor color="{getColor(0, 6, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="605" y="105" width="90" height="90">
<fill>
<SolidColor color="{getColor(1, 6, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="605" y="205" width="90" height="90">
<fill>
<SolidColor color="{getColor(2, 6, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="605" y="305" width="90" height="90">
<fill>
<SolidColor color="{getColor(3, 6, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="605" y="405" width="90" height="90">
<fill>
<SolidColor color="{getColor(4, 6, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
<Ellipse x="605" y="505" width="90" height="90">
<fill>
<SolidColor color="{getColor(5, 6, _boardData)}"/>
</fill>
<stroke>
<SolidColorStroke caps="none" weight="1" joints="miter" miterLimit="4"/>
</stroke>
</Ellipse>
</Group>
</Graphic>

应用mxml:
<?xml version="1.0" encoding="utf-8"?>
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo"
xmlns:comp="components.*"
width="100%" height="100%"
    initialize="board.newGame()">
<fx:Script>
<![CDATA[
import mx.graphics.SolidColor;
private function getColor(playerOneTurn:Boolean):SolidColor
{
return new SolidColor(playerOneTurn?board.playerOneColor:board.playerTwoColor);
}
]]>
</fx:Script>
<s:layout>
<s:BasicLayout/>
</s:layout>
<s:Panel title="Only connec!" x="10" y="10" width="100%" height="100%">
<s:layout>
<s:VerticalLayout paddingLeft="5" paddingTop="5"
  paddingBottom="5" paddingRight="5"/>
</s:layout>
<s:HGroup verticalAlign="middle">
<s:Button label="New Game" click="board.newGame()"/>
<s:Ellipse width="20" height="20" fill="{getColor(board.playerOneTurn)}"/>
<s:Label text="Player {board.playerOneTurn?'1':'2'} Turn"/>
</s:HGroup>
<comp:BoardDisplay id="board"/>
</s:Panel>
</s:Application>
  • 大小: 29.2 KB
分享到:
评论
1 楼 荷尔萌 2013-10-14  
我的智商太低吗= =不知道这个游戏怎么玩

相关推荐

    Flex4-in-a-day

    Flex4在图形表现上也有了显著的提升,引入了MXML Graphics和FXG(Flash XML Graphics),让开发人员可以更方便地创建和管理复杂的图形。同时,CSS(层叠样式表)的引入和Flex Themes(主题)的创建和应用,也使得...

    CVE-2018-9995_dvr_credentials.rar_CVE-2018_FXG_burp CVE-2018-999

    标题中的"CVE-2018-9995_dvr_credentials.rar_CVE-2018_FXG_burp CVE-2018-999"提及了几个关键概念,首先,CVE(Common Vulnerabilities and Exposures)是用于识别网络安全漏洞的标准化系统。"CVE-2018-9995"指的是...

    Flex3与Flex4对比

    - **FXG支持**:FXG是一种图形交换格式,Flex4支持FXG格式的导入和导出,这为设计人员提供了更多的灵活性。 - **更新的布局模型、2D旋转、3D支持**:Flex4在布局模型上进行了改进,并增加了对2D旋转和3D效果的支持,...

    flex4新特性展示(中文版)

    - **FXG**:FX Graphics(FXG)是一种轻量级的矢量图形格式,用于在Adobe Flex应用程序中创建和嵌入矢量图形资源。FXG的引入进一步提升了开发效率,使得设计师可以直接使用该格式导出图形资源而无需经过复杂的转换...

    RIAMeeting Flex4培训纪要

    - **FXG**:FXG是一种用于描述矢量图形的语言,Flex4增加了对FXG的支持,使图形设计更加灵活。 - **编译器性能**:Flex4的编译器性能得到了显著优化,加快了应用的构建速度。 - **双向绑定**:Flex4支持双向数据绑定...

    Flex4 SDK 新特性

    - **MXML图形元素与FXG**:Flex 4引入了新的MXML图形元素,允许开发者直接在MXML中定义图形对象,并支持FXG格式的导入导出,进一步增强了Flex在图形处理方面的能力。 - **高级CSS Selector**:为了更好地控制样式,...

    flex4新特性展示中文版

    通过引入全新的Spark组件模型、MXML2009语言、FXG格式等,Flex4实现了框架的全面进化。其中,Spark组件模型是Flex4的一个重要革新,它优化了组件的渲染和内存管理,使得应用运行更加流畅,同时支持更复杂的用户界面...

    flex英文帮助文档(非常详细)

    - **FXG 和 MXML 图形**:讲述了如何使用 FXG 文件或 MXML 代码来创建图形元素。 - **效果介绍**:讲解了 Flex 中的效果系统及其基本概念。 - **Spark 效果**:介绍了 Spark 框架下的效果实现方法。 - **使用 MX ...

    FLEX4权威指南,随书资源代码

    随书资源代码包含了书中各个章节的实例代码,读者可以通过这些代码深入了解Flex 4的使用方法,学习如何创建和管理项目,设置组件属性,处理事件,实现数据绑定,以及运用动画效果等。通过实际操作,能加深对Flex 4...

    cairngorm2.2.1 与 flex4的集成. error错误解决

    在Flex 4中,你可以使用ActionScript类来实现这些组件,而不是依赖Flex的MXML组件。Cairngorm提供了如`Command`, `Locator`, `Event`, `Proxy`等核心类,它们是构建MVC结构的基础。 3. **处理“error”错误**: ...

    flex_4.6_help.pdf

    - **FXG和MXML图形**:用于创建矢量图形。 - **效果介绍**:包括动画和其他视觉效果。 - **Spark效果**:专为 Spark 组件设计的效果。 - **使用MX效果**:适用于旧版 MX 组件的效果。 - **视图状态**:根据条件更改...

    PyPI 官网下载 | fxg2svg-0.1.3b0-py3.4.egg

    “fxg2svg”是一个Python库,主要功能是将FXG(Flex Graphics)格式的文件转换为SVG(Scalable Vector Graphics)格式。FXG是一种用于描述二维图形和图像的数据格式,常用于Adobe Flex项目中。而SVG则是一种开放标准...

    Flex 4.6文档

    - **图形和动画**:介绍了如何使用FXG和MXML图形来增强UI,以及如何添加各种视觉效果。 以上仅为Flex 4.6部分核心知识点的概述,实际上Flex 4.6包含的内容远不止这些。对于想要深入了解Flex 4.6的开发者而言,官方...

    jate.rar_flex

    通常,一个Flex项目会包含FLA或FXG(图形交换格式)文件用于设计界面,AS3源代码文件(.as)用于编写业务逻辑,配置文件(如flex-config.xml)用于编译设置,以及可能的资源文件(如图片、声音或XML数据)。...

    fxg 矢量图编辑工具

    fxg 矢量图编辑工具 实现基本绘图功能,可导出fxg源码

    flex4.5学习笔记

    ### Flex4.5学习笔记知识点总结 #### 一、Flex基础——布局 **知识点1:Flex布局** - **垂直布局** (`s:VerticalLayout`): 控件垂直排列。 - **水平布局** (`s:HorizontalLayout`): 控件水平排列。 - **平铺布局**...

    Python库 | fxg2svg-0.2.2.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:fxg2svg-0.2.2.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    Advanced Flex 4(一) source codes

    这是Advanced Flex4 第一章节的所有source codes。为FXG格式的工程文件。

Global site tag (gtag.js) - Google Analytics