skip to main |skip to sidebar
显示标签为“flex”的博文。显示所有博文
显示标签为“flex”的博文。显示所有博文

2008-02-03

[Flex]把 Sprite 添加到 Canvas 里的方

Flex FrameworkCanvas 是无法添加 Sprite 等非 UI 组件的 DisplayObject的。但有变通的办法。

1.使用 Adaptor 模式

Sprite 添加到 UIComponent,再把 UIComponent 添加到 Canvas

代码:

var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0xFFCC00);
mySprite.graphics.drawCircle( 40, 40, 40 );
var UIRef:UIComponent = new UIComponent();
myUI.addChild(UIRef);
UIRef.addChild(mySprite);

2.使用 rawChildren

使用 Canvas.rawChildren

代码:

var mySprite:Sprite = new Sprite();
mySprite.graphics.beginFill(0xFFCC00);
mySprite.graphics.drawCircle( 40, 40, 40 );
myUI.rawChildren.addChild(mySprite);

2007-10-14

[AS3]位图的色阶控制(1) -- 得到色阶

色阶为位图的颜色分布的图。做过图形处理的应该很熟悉。

比如下图:上面为原图,下面为色阶。

Historgram

得到方法:

  1. 灰色化。把各个通道求平均。用ColorMatrixFilter即可。
  2. 用threshold来得到颜色分布。threshold的返回值为匹配的像素的个数。

代码:


package {
    import flash.display.*;
    import flash.filters.ColorMatrixFilter;
    import flash.geom.Point;

    public class TestBitmap extends Sprite {
        [Embed(source="023.jpg")]
        private var SampleImage:Class;

        public function TestBitmap() {
            var bmd:BitmapData = Bitmap(addChild(new SampleImage())).bitmapData;
            var s:Sprite = new Sprite();
            createHistogram(bmd,s);
            addChild(s).y = bmd.height + 10;
        }

        //生成色阶
        private function createHistogram(bmd:BitmapData, s:Sprite):void {
            //灰度画
            var cmf:ColorMatrixFilter = new ColorMatrixFilter(
                [1 / 3, 1 / 3, 1 / 3, 0, 0, 
                 1 / 3, 1 / 3, 1 / 3, 0, 0, 
                 1 / 3, 1 / 3, 1 / 3, 0, 0]
            );
            var bmd2:BitmapData = bmd.clone();
            bmd2.applyFilter(bmd2, bmd2.rect, new Point(), cmf);

            //用threshold来得到颜色分布
            var values:Array = [];
            for(var i:int = 0; i < 0x256; i++) {
                values[i] = bmd2.threshold(bmd2, bmd2.rect, new Point(), "==", i, 0, 0xff, false);
            }
            bmd2.dispose();

            //画色阶
            var max:int = bmd.width * bmd.height / 50;
            s.graphics.lineStyle(1);
            for(i = 0; i < 256; i++) {
                s.graphics.moveTo(i, 100);
                s.graphics.lineTo(i, Math.max(0, 100 - values[i] / max * 100));
            }
        }
    }
}

2007-10-09

Adobe AIR的电子署名

AIR Beta 2以后,在打包时必须制作电子署名。电子署名的目的为:

  1. 确认包未被修改(比如说被绑定病毒)
  2. 确认包的创建者。

如果未署名,将会生成扩展名为airi的文件,这个如果不用adt等来署名的话,将无法安装到AIR运行环境。

署名可以使用CA发行的或者自己的署名的证明书。用自己的署名的证明书的话无法用于以上的确认包的创建者的目的。

注意,电子署名并不保证程序能够正常运行。并且,因为现在为Beta,所以并不能保证电子署名本身功能的正确性。

自己的署名的证明书的制作

自己的署名的证明书可以用 Flex Builder 3 Beta 2,Flash CS3/Dreamweaver CS3 的 AIR Beta 2用的扩展插件来制作。注意,千万别忘了密码

用Flex Builder 3 Beta 2来制作

执行Export向导,当显示"Digital Signature"的画面时,点"Create..."按钮。再输入署名,密码,生成的文件,点OK。注意在名字里可以使用的只有英数字。

用Flash CS3来制作

选择AIR->Application & Installer Settings打开设置窗口,并且确认 Sign the AIR file with a digital certificate 是选中的。再点击"Digital Signature"右边的 "Change..."按钮。这将会打开设定署名的窗口。以后与Flex Builder相同。(可以选择1024 Bit与2048 Bit)

用Dreamweaver CS3来制作

选择Site->AIR Application Settings...打开设置窗口。再点击"Digital signature"右边的"Set..."。这将会打开设定署名的窗口。以后与Flash CS3相同。

2007-10-01

Flex 3 beta 2

Flex 3 Beta 2 在Adobe Lab 发布了。详细参见(Adobe FlexBuilder@Labs, Adobe Flex SDK@Labs

根据Flex 3 Planning的最新信息,Flex 3 的时间表如下:

  • April 9, 2007 M1 Release (Alpha)
  • June 11, 2007 M2 Release (Beta 1)
  • October M3 Release (Beta 2) - Feature Complete
  • Late 2007 M4 - Release Candidate
  • Early 2008 Final Release

本次的内部版本为M3,即第三个测试版本。功能已经完全实装了。在今年内将发布RC版本,即M4。

使用CrossDomain RSL时,必须使用一起发布的Flash Player(9.0.60.235)。这个Flash Player 为Beta版。

Flex Skin Design Extensions

为CS3的产品的Flex 3 Skin制作的导入的功能扩展也发布了。目前的版本为Pre-release。提供了Photoshop, Illustrator, Flash, Fireworks的功能扩展。

下载地址(Flex Skin Design Extensions@Labs Downloads

2007-09-02

用Ant来打包(compc)flex的源文件为SWC

直接用compc来打包flex源文件是很复杂且繁琐的事。但用了Ant,在Eclipse里一切都变为按一个键。

compc.xml:

<!--/////////////////////////////////////////////////////////////////////////////
//Copyright 2007 Advanced Flex Project http://code.google.com/p/advancedflex/.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
///////////////////////////////////////////////////////////////////////////// -->
<project name="Compc build" default="main">
<!-- defines all values for the Compc compiler -->
<property file="compc.properties" />
<!-- main target: cleans and compiles ASDocs -->
<target name="main" depends="clean, log, compc" />
<!-- deletes and recreates the compc directory -->
<target name="clean">
<delete dir="${output.dir}" failonerror="true"/>
<mkdir dir="${output.dir}"/>
</target>
<!-- runs the compc.exe compiler on the source -->
<target name="compc">
<exec executable="${compc.exe}" failonerror="true">
<arg line="-include-sources '${src}'" />
<arg line="-output '${output.dir}/${output.file}'" />
</exec>
</target>
<!-- writes compc output to log file: compc-log.log -->
<target name="log">
<record name="${output.dir}/compc-log.log" action="start" append="true" />
</target>
</project>

compc.properties:

################################################################################
##Copyright 2007 Advanced Flex Project http://code.google.com/p/advancedflex/.
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
############################################################################### #compc.exe的位置
compc.exe =C:/Program Files/Adobe/Flex Builder 2 Plug-in/Flex SDK 2/bin/compc.exe #源文件的位置
src = #输出的位置
output.dir = #输出的文件名
output.file =

2007-07-26

Flex 2.0.1 Hotfix 3

Flex 2.0.1 SDK Hotfix 3 在 US 的支持中心里发布了。

利用在US发布的LCDS 2.5.1时,需要添加Hotfix 3。注意Hotfix 3是专门针对LCDS 2.5.1的,使用FDS 2.0.1时最好不要添加。

其他的注意事项:

  • 不支持Flex Builder 2.0
  • 添加Hotfix 3前,需要添加Hotfix 2。
  • 如果没有出现Hotfix修正的问题,最好不要添加。

详细看下面:

2007-06-09

用Ant创建ASDoc

Ant创建ASDoc既方便又高效。

首先,在Eclipse的一个Project里,新建一个如下的asdoc.properties:([*]替换成你的实际内容)

#asdoc.properties

asdoc.exe     =[asdoc.exe的地址]
src           =[源码的地址]
main.title    =[主标题]
window.title  =[窗口标题]
output.dir    =[输出的地址]

再新建一个如下的asdoc.xml:


<!-asdoc.xml--->
<project name="ASDoc build" default="main">
 <!-- 定义ASDoc的变量 -->
 <property file="asdoc.properties" />
 <!-- main target:删除并编译Doc -->
 <target name="main"
 depends="clean, log, create-docs" />
 <!-- 删除以前的Doc -->
 <target name="clean">
  <delete dir="${output.dir}" />
  <mkdir dir="${output.dir}" />
 </target>
 <!-- 编译Doc -->
 <target name="create-docs">
  <exec executable="${asdoc.exe}" failonerror="true">
   <arg line="-doc-sources '${src}'" />
   <arg line="-main-title '${main.title}'" />
   <arg line="-window-title '${window.title}'" />
   <arg line="-output '${output.dir}'" />
  </exec>
 </target>
 <!-- 写历史(log)文件 -->
 <target name="log">
  <record name="${output.dir}/asdoc-log.log"
 action="start" append="true" />
 </target>
</project>

最后在用Ant编译asdoc.xml。

出来了吗?

2007-05-29

advancedflex - debugger framework 0.1 alpha发布

debugger framework ver 0.1 alphaDbug Project 的第一个公开的框架

它是一个为了Flash&Flex&Apollo测试的框架。

实现的:

  • advancedflex.debugger //公用库。
  • advancedflex.debugger.errors //公用库的错误类库。
  • advancedflex.debugger.display //包含了用AS3.0写的,显示一些信息(比如FPS)的DisplayObject。
  • advancedflex.debugger.display.mxml //包含了用MXML写的,显示一些信息(比如FPS)的组件。

未实现的:

  • advancedflex.debugger.aut //Actionscript Unit Test framework(有GUI,可以用FlexAnt启动)。
  • advancedflex.debugger.logging //Logging framework,增强了mx.logging的框架(有GUI,支持HTML标签)。
  • advancedflex.debugger.ui //用于与GUI窗口(Apollo或Flex写的)通讯的库。

下载

2007-05-20

XML/XSL+SWFObject=Flex!

震撼!

XML/XSL + SWFObject(Javascript) = Flex!

源程序是用XML写的,但用了XSLT技术和js,XML变为了Flex

  • Flex对搜索引擎不友好将会一去不复返
  • Flex的大小将减小很多(SWFObject可以缓存,每次只需下载XML即可)。

但它也不是十全十美的。因为它必须用js。希望以后能有所改变。

Flex over XML/XSL

2007-05-06

Flex2 Tag for JSP

以前在Adobe lab发布了一个Flex Tag Library for JSP的东西,但好像关注的人很少。所以我向大家介绍一下。

使用JSP Tag Library就能在JSP里镶入MXML。这个功能虽包含在flex1.x里,但flex2却没包含。

安装方法:

  1. 停止FDS(它需要FDS 2.0.1,Express版可)。
  2. 下载 (flex2_tag_library_for_jsp.zip: 31KB)。
  3. 把下载的zip文件里的flex-bootstrap-jsp.jar拷贝到/WEB-INF/lib。
  4. 把下载的zip文件里的flex-webtier-jsp.jar拷贝到/WEB-INF/flex/jars。
  5. 在web.xml文件添加以下内容。
    Code:XML
    <taglib>
      <taglib-uri>FlexTagLib</taglib-uri>
      <taglib-location>/WEB-INF/lib/flex-bootstrap-jsp.jar</taglib-location>
    </taglib>
  6. 重启动FDS。

使用方法:

标签的声明:

Code:jsp
<%@ taglib uri="FlexTagLib" prefix="mm" %>

镶入MXML,类似于jsp:include,但它包含的不是jsp,是MXML:

Code:jsp
<mm:mxml source="flexApp.mxml"/>

在jsp里插入MXML代码:

Code:jsp
<mm:mxml>
  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*">
    <mx:Text text="Hello World" />
  </mx:Application>
</mm:mxml>

还可以动态地编译代码: *因为他不能缓存,所以对开销很大,要注意。

Code:jsp
<mm:mxml>
  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*">
    <% if (request.isUserInRole("admin")) { %>
      <AdminConsole/>
    <% } else { %>
      <UserConsole/>
    <% } %>
  </mx:Application>
</mm:mxml>

往flex程序里传参数:

Code:jsp
<mm:mxml source="flashvarTest.mxml" width="400" height="200">
  <mm:flashvar name="javaVersion" value='<%= System.getProperty("java.version") %>' />
  <mm:flashvar name="currentDate" value="<%= new java.util.Date().toString() %>"/>
</mm:mxml>

这里向flashvarTest传了javaVersioncurrentDate两个参数。在flex程序里用Application.application.parameters.valueName的形式来访问。

Sample:

Code:jsp
<%@ taglib uri="FlexTagLib" prefix="mm" %>
<mm:mxml height="300" width="600">
  <mm:flashvar name="javaVersion" value='<%= System.getProperty("java.version") %>' />
  <mm:flashvar name="currentDate" value="<%= new java.util.Date().toString() %>"/>
  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" >
    <mx:VBox>
      <mx:HBox>
        <mx:Label text="Java version: "/>
        <mx:Label text="{Application.application.parameters.javaVersion}" fontWeight="bold"/>
      </mx:HBox>
      <mx:HBox>
        <mx:Label text="Current Time: "/>
        <mx:Label text="{Application.application.parameters.currentDate}" fontWeight="bold"/>
      </mx:HBox>
    </mx:VBox>
  </mx:Application>
</mm:mxml>