www.adobeshow.com
标签 Tag : as

基于Actionscript3的Google Map多点触摸全攻略

<Category: ActionScript 3.0, Adobe, Flash, Flex, Flex3, Flex4, 多点触摸> 发表评论

这个教程的目的是实现对GoogleMap的多点触摸。
需要的软件:
1,安装touchlib,请用SVN checkout下面这个网址:http://touchlib.googlecode.com/svn/trunk/ 注意,要用SVN。

2,FlashCS3或者FlashCS4.

3,下载GoogleMapAPI,请到这里下载google map SDK

4,请到这里下载下面4个文件。TUIOObject.as,googlemap.fla,googlemap.as,TUIO.as;

5,如果没有多点触摸平台,请下载模拟器
到此,文件都准备完毕,我们正式开工:

1,在D:\Program Files\Adobe\Adobe Flash CS3\zh_tw\Configuration\Components文件夹下新建一个文件夹,起名为”Google”,;

然后,把下载的GoogleMap SDK解压缩,找到一个叫 lib 文件夹,将文件夹下面的map_1_9.swc(注意,版本号可能有不同,比如,可能是map_1_8.swc,这不影响)文件拷贝到 D:\Program Files\Adobe\Adobe Flash CS3\zh_tw\Configuration\Components\Google文件夹下面。

注意,这一步的目的是往Flash里添加GoogleMap组件,所以,上面的文件地址可能与你电脑上的地址有出入,你根据自己的情况来。

2,建立GoogleMap的工作文件夹。

请到..\touchlib\AS3\int\app文件夹里,新建一个文件夹,起名为 GoogleAPI;

再到..\touchlib\AS3\int文件夹里面,把一个叫”flash”的文件夹拷贝到 ..\touchlib\AS3\int\app\GoogleAPI文件夹里面;

下载下来的TUIO.as文件替换 ..\touchlib\AS3\int\flash\events文件夹里面的TUIO.as;

下载下来的TUIOObject.as替换..\touchlib\AS3\int\flash\events文件夹里面的TUIOObject.as;

3,把googlemap.as和googlemap.fla文件拷贝到..\touchlib\AS3\int\app\GoogleAPI 下面。

4,打开googlemap.fla;此处注意,你可能需要从新导入GoogleMap library,方法:falsh>>window>>components,或者直接快捷键: Ctrl+F7,找到Google,然后把Google选项下的组件拖到舞台。

5,如果没有模拟起,请打开模拟器;

6,Ctrl+Enter, 发布swf文件,这时,swf文件应该要载入GoogleMap,然后,通过模拟器对GoogleMap实现多点触摸。

本文来自: 基于Actionscript3的Google Map多点触摸全攻略

8 Classical ActionScript Classes About BitMap

<Category: ActionScript 2.0, ActionScript 3.0, Adobe, Flash, Flex, Flex3, Flex4> 发表评论

Bitmap is an often used graphics file format in program development. Then it seems how to master it is very important. In fact there are many very useful classes about bitmap can help you to easily create a Bitmap objects. Following we have collected 8 classical BitMap classes for your reference. Hope you can enjoy them.

AS3 Scale9 Bitmap

AS3 Scale9 Bitmap is helper class that lets you create scale9 sprites with bitmap data fill – originally this was not possible in Flash 9. The helper class creates a “fake” scale 9 sprite containing 9 shapes that scale according to user-defined scaling matrix. Extremely useful for user interface work (creating buttons, scalable UI elements etc.).

AS3 bitmap mosaic class

This class will allow you to create a pixellated copy of any display object. It allows for varying pixel sizes and caching of rendered pixels so you don’t have to redraw them every time.

Active Window Blur

It has detail code and examples show how the class works.

Animated Bitmap Class

The AnimatedBitmap class provides functionality for Bitmap objects that are animated by using a series of still images. When creating a new AnimatedBitmap you provide a BitmapData object that contains an image that consists of the ’single-frame’ images for the animation.

CollisionDetection Class 

CollisionDetection class is really simple to work with, there is a single static method called checkForCollision with four parameters. movieClip1, movieClip2 – The MovieClip instances to check for collision. alphaTolerance – a number from 0 to 255 that specifies the transparency tolerance when testing the collision. A higher number will increase the tolerance (ie. allow more transparent parts of the MovieClip to register collisions). Defaults to 255.

DistortImage Class 

It is an updated version of the original DistortImage class for AS2, which allows you to programmatically distort images.

ImageLoader

 ImageLoader is a straightforward image loader. It simplifies the job of loading images by automatically creating a list of images being loaded, controlling its queue with priority features (by way of the LoadingQueue class), and by caching images locally using BitmapData instances. This means that when you try to load a new image, it actually loads the image, saves its BitmapData, and attaches the image to the container (with smooth turned on by default).

Reflection class

 It is a simple class for creating a reflection below any type of displayObject in AS3.

本文来自: 8 Classical ActionScript Classes About BitMap

触摸屏开源技术

<Category: TouchLib> 发表评论

开源网站

http://nuigroup.com/touchlib/

http://wiki.nuigroup.com/

svn:

http://touchlib.googlecode.com/svn/trunk/

本文来自: 触摸屏开源技术

三次样条插值法AS代码

<Category: ActionScript 2.0, ActionScript 3.0, Adobe, Flash> 发表评论

三次样条插值是在曲线拟合中用到得比较好得算法,根据的是曲线的光滑的必要条件:二阶导连续.
下面是主要的算法代码:

//===============三次样条插值======================================
function Hermite(arr:Array):Array
{
        var history_arr:Array = new Array();
        history_arr[0] = arr[1];
        //trace(arr[1].y)
        for (var i = 1; i<arr.length/3-1; i++) {
                history_arr[i] = arr[i*3];
        }
        history_arr.push(arr[arr.length-1]);
        var N:Number = history_arr.length;
        //trace(N);
        var M:Number = 3*N+3;
        var H:Number = history_arr[N-1].x/M;
        var x:Array = new Array();
        var y:Array = new Array();
        var f:Array = new Array();
        var h:Array = new Array();
        var a:Array = new Array();
        var b:Array = new Array();
        var A:Array = new Array();
        var B:Array = new Array();
        var m:Array = new Array();
        var s:Array = new Array();
        var xx:Array = new Array();
        var record:Array = new Array();
        var tmp:Array = new Array();
        for (var i = 0; i<N; i++) {
                x[i] = history_arr[i].x;
                y[i] = history_arr[i].y;
                h[i] = 0;
                a[i] = 0;
                b[i] = 0;
                A[i] = 0;
                B[i] = 0;
        }
        h[0] = x[1]-x[0];
        a[0] = 1;
        b[0] = 3*(y[1]-y[0])/h[0];
        A[0] = -a[0]/2;
        B[0] = b[0]/2;
        for (var i = 1; i<N-1; i++) {
                h[i] = x[i+1]-x[i];
        }
        for (var i = 1; i<N-1; i++) {
                a[i] = h[i-1]/(h[i-1]+h[i]);
                b[i] = 3*((1-a[i])*(y[i]-y[i-1])/h[i-1]+a[i]*(y[i+1]-y[i])/h[i]);
        }
        for (var i = 1; i<N-1; i++) {
                A[i] = -a[i]/(2+(1-a[i])*A[i-1]);
                B[i] = (b[i]-(1-a[i])*B[i-1])/(2+(1-a[i])*A[i-1]);
        }
        m[N-1] = (b[N-1]-(1-a[N-1])*B[N-2])/(2+(1-a[N-1])*A[N-2]);
        for (var i = N-2; i>=0; i–) {
                m[i] = A[i]*m[i+1]+B[i];
        }
        for (var k = 1; k<=M; k++) {
                xx[k] = H*k;
                for (var i = 0; i<N-1; i++) {
                        if (xx[k]>=x[i] && xx[k]<=x[i+1]) {
                                s[k] = (1+2*(xx[k]-x[i])/(x[i+1]-x[i]))*Math.pow((xx[k]-x[i+1])/(x[i]-x[i+1]), 2)*y[i]+(1+2*(xx[k]-x[i+1])/(x[i]-x[i+1]))*Math.pow((xx[k]-x[i])/(x[i+1]-x[i]), 2)*y[i+1]+(xx[k]-x[i])*Math.pow((xx[k]-x[i+1])/(x[i]-x[i+1]), 2)*m[i]+(xx[k]-x[i+1])*Math.pow((xx[k]-x[i])/(x[i+1]-x[i]), 2)*m[i+1];
                                record.push({hk:k, hs:s[k]});
                        }
                }
        }
        for (var i = 0; i<record.length; i++) {
                tmp.push({x:record[i].hk*H, y:record[i].hs});
        }
        for (var i = 0; i<history_arr.length; i++) {
                tmp.push({x:history_arr[i].x, y:history_arr[i].y});
        }
        tmp.sortOn(["x"], [Array.NUMERIC]);
        for (var i = 0; i<tmp.length; i++) {
                //trace(“tmp["+i+"]:=”+tmp[i].x);
        }
        return tmp;
}

 

主要的思想是取一段不光滑曲线的若干个点,根据这些点生成一些插入点,然後根据这个插入点和取出的曲线的点连结起来,这样就能得到一条光滑的曲线了
这个函数我写的是一个单调增的,当然现实的情况不止是单调增这么简单,也有可能单调减或复合型的

本文来自: 三次样条插值法AS代码