月度存档: 6 月 2011

原创:as3isolib_中文教程_006

原文地址:http://code.google.com/p/as3isolib/wiki/as3isolib_tutorial_006

ISceneRenderers可以给 IsoScene自定义样式 和布局 ,当前有两种ISceneRenderers,他们能处理场景上子对象的布局,他们能自定义整个场景和子对象的风格(比如设置阴影和别的效果),ISceneRenderer帮助开发者自定义布局 和造型,而不仅限于已有类。

实现作用于场景的 ISceneRenderer类的方式中用到了工厂方法(这个概念借鉴了Flex SDK的工厂接口和类)

以下示例展示了ISceneRenderer如何用作场景的风格的渲染器:

注:google上代码的小小错误被姐修正了,嗯!

package

{

/**

* …

* @author amyflash.com

*/

import as3isolib.core.ClassFactory;

import as3isolib.core.IFactory;

import as3isolib.display.IsoView;

import as3isolib.display.primitive.IsoBox;

import as3isolib.display.renderers.DefaultShadowRenderer;

import as3isolib.display.scene.IsoGrid;

import as3isolib.display.scene.IsoScene;

import flash.display.Sprite;

public class IsoApplication6 extends Sprite

{

public function IsoApplication6 ()

{

var scene:IsoScene = new IsoScene();

scene.hostContainer = this;

var g:IsoGrid = new IsoGrid();

g.showOrigin = false;

scene.addChild(g);

var box:IsoBox = new IsoBox();

box.setSize(25, 25, 25);

box.moveBy(20, 20, 15); //feature request added

scene.addChild(box);

//var factory:IFactory = new ClassFactory(DefaultShadowRenderer);

var factory:as3isolib.core.ClassFactory = new as3isolib.core.ClassFactory(DefaultShadowRenderer);

factory.properties = { shadowColor:0x000000, shadowAlpha:0.15, drawAll:false };

// factory.properties = { shadowColor:0x000000, shadowAlpha:1, drawAll:false };

scene.styleRenderers = [factory];

scene.render();

var view:IsoView = new IsoView();

view.y = 50;

view.setSize(150, 100);

//view.scene = scene; //look in the future to be able to add more scenes

view.addScene(scene);

addChild(view);

}

}

}

如果因为某种原因,你想要不同颜色的阴影,可以简单的修改对应代码如下:

factory.properties = { shadowColor:0x000000, shadowAlpha:1, drawAll:false };

IsoScenes只能有一个ISceneRenderer类型的布局渲染器,但是可以有多个风格渲染器;风格渲染器越多耗cpu资源越大,风格渲染的顺序与它们被添加的顺序一致。

 

原创:as3isolib_中文教程_008&007

008就是告诉你怎么在flex中用as3isolib,只要用过flex的人肯定都知道啦,所以姐也不啰嗦了。所以下面重点说007,古往今来,重头戏都是007,比如黄金眼007,大内密探007啦啦啦,不扯远了,原文地址:

http://code.google.com/p/as3isolib/wiki/as3isolib_tutorial_007

下面是翻译内容:

这个教程用到了 Grant Skinner的 GTween 库. 你能在这下载 到这个库的东东

大部分开发者都能找到各种层次的用as3Isolib做的交互式应用,这儿有个例子告诉你怎么用grid和box快速的建立一个简单的交互应用,点击grid上的任何一个cell,box都会朝那个cell运动。

google上的代码有点小问题,所以姐再次很勤奋的倒腾出一个能编译通过的版本,哈哈

以下代码在flashdevelop下编译通过,配置环境:sdk4,flashplayer10

package
{
import as3isolib.core.IIsoDisplayObject;
import as3isolib.display.IsoView;
import as3isolib.display.primitive.IsoBox;
import as3isolib.display.scene.IsoGrid;
import as3isolib.display.scene.IsoScene;
import as3isolib.geom.IsoMath;
import as3isolib.geom.Pt;

import com.gskinner.motion.GTween;

import eDpLib.events.ProxyEvent;

import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;

/**
* …
* @author amyflash.com
*/
public class IsoApplication7 extends Sprite
{
private var box:IIsoDisplayObject;
private var scene:IsoScene;

public function IsoApplication7 ()
{
scene = new IsoScene();

var g:IsoGrid = new IsoGrid();
g.showOrigin = false;
g.addEventListener(MouseEvent.CLICK, grid_mouseHandler);
scene.addChild(g);

box = new IsoBox();
box.setSize(25, 25, 25);
scene.addChild(box);

var view:IsoView = new IsoView();
view.clipContent = false;
view.y = 50;
view.setSize(150, 100);
view.addScene(scene); //以后可以增加更多场景
addChild(view);

scene.render();
}

private var gt:GTween;

private function grid_mouseHandler (evt:ProxyEvent):void
{
var mEvt:MouseEvent = MouseEvent(evt.targetEvent);
var pt:Pt = new Pt(mEvt.localX, mEvt.localY);
IsoMath.screenToIso(pt);

if (gt)
gt.end();

else
{
gt = new GTween();
gt.addEventListener(Event.COMPLETE, gt_completeHandler);
}

gt.target = box;
gt.duration = 0.5;

//gt.setValues({x:pt.x, y:pt.y});//GTween_v2_01版本中用这个
gt.setProperties({x:pt.x, y:pt.y});
gt.play();

if (!hasEventListener(Event.ENTER_FRAME))
this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}

private function gt_completeHandler (evt:Event):void
{
this.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
}

private function enterFrameHandler (evt:Event):void
{
scene.render();
}
}

}

原创:as3isolib_中文教程_009

今天上海下大暴雨,周末不想出去玩了,在家学习好了额,别人学习写教程都是从001开始,姐喜欢逆学,希望能学到欧阳锋的功夫,但是不要像欧阳锋那样疯癫就好了,哈哈。。。(如果你是高手,那你就随便看看了,如果你是新手那还是等我把001翻译好了再从001开始看吧,姐也是为你好哈)

这个教程大部分从googlecode上翻译过来的,夹杂姐的些许感慨,英文好的还是建议看原文哈,不是姐对姐的英文不自信,而是姐觉得有责任让丫好好学习下英文,o(∩_∩)o 哈哈,英文原文地址:

http://code.google.com/p/as3isolib/wiki/as3isolib_tutorial_009

开发者可以通过工厂类的实例来进行渲染视图,以使api更为灵活。 As3isolib自带默认渲染器,这些渲染器的代码可以在包as3isolib.display.renderers 中找到 值得注意的是IViewRenderer类。 IViewRenderer类旨在协助渲染视图,这个视图在大多数情况下和视图的场景相关。 下面的例子将说明如何使用IViewRenderers。

这第一个例子是没有用到IViewRenderers。 效果就是本来不应该在边界外出现的图像出现了。

第二个例子 展示了默认渲染器DefaultViewRenderer的使用,这东东 遍历 目标视图 场景的 子对象 ,并确定 他们 是否 可见区域,不在可见区域的子对象都被移除掉了。

最后一个例子综合使用DefaultViewRenderer和ViewBoundsRenderer,ViewBoundsRenderer 用于绘制 边界 矩形(可以画边界矩形) ,来限定场景子对象的边界,而不管场景子对象是否在显示列表里出现。

按照google上的例子,姐编译了下,愣是没看出第二个例子和最后一个例子效果上有啥区别,姐只好跑去看了下ViewBoundsRenderer和DefaultViewRenderer的类源码,这才恍然大悟,原来DefaultViewRenderer就是限定显示区域,而ViewBoundsRenderer就是给舞台上的对象画边框,所以姐很勤奋地修改了下google的源码,这样很容易看到区别了,啦啦啦

注:姐列出来的代码在flashdevelop下均编译通过,配置环境:sdk4,flashplay10

package
{
/**
* …
* @author amyflash.com
*/
import as3isolib.core.ClassFactory;
import as3isolib.display.IsoView;
import as3isolib.display.primitive.IsoBox;
import as3isolib.display.renderers.DefaultViewRenderer;
import as3isolib.display.renderers.ViewBoundsRenderer;
import as3isolib.display.scene.IsoGrid;
import as3isolib.display.scene.IsoScene;

import flash.display.Sprite;

public class IsoApplication9 extends Sprite
{
public function IsoApplication9 ():void
{
var box:IsoBox = new IsoBox();
box.moveTo(15, 15, 0);
var box2:IsoBox = new IsoBox();
box2.moveTo(35, 15, 0);

var grid:IsoGrid = new IsoGrid();

var scene:IsoScene = new IsoScene();
scene.addChild(box);
scene.addChild(box2);
scene.addChild(grid);
scene.render();

var view:IsoView = new IsoView();
view.setSize(150, 100);
view.addScene(scene);
/*例子 1
view.clipContent = false;*/
/*例子2
view.clipContent = true;
view.viewRenderers = [new ClassFactory(DefaultViewRenderer)];*/
//例子 3
view.clipContent = true;
var vbr:ClassFactory = new ClassFactory(ViewBoundsRenderer);
var t:ViewBoundsRenderer = vbr.newInstance();
t.renderView(view);
view.viewRenderers = [new ClassFactory(DefaultViewRenderer), vbr];
addChild(view);
}
}
}

FlashDevelop 快捷键

用了一段时间的flex(flash builder),觉得还是flashdevelop好啊,flex居然没有链接返回的设置,只能按住ctrl,点相应的变量查看,看完了没法返回到上一次查看的地方了,据说flash builder 4.5 加入了快捷键可以这样搞了,但是人家flashdevelop早就可以这样搞了。。。。,所以姐决定在家还是倒腾fd好了,看代码方便。

Development shortcuts

Ctrl+SPACE = Autofill.
Ctrl+Alt+SPACE = Autofill with class name.
Ctrl+Shift+SPACE = Shows method parameters hint if cursor is inside method call.
Ctrl+Shift+1 = Template generation. You can generate:

  • Getters and setters if you are on field definition.
  • Class field if you are on undeclared variable.
  • Function if you are on undeclared function.
  • Event handler if you are on undeclared event handler.
  • All public methods and properties inherited by current class from the interface under cursor

Ctrl+B = Snippet insertion. Snippet is unparameterized code template. In instance, condition or loop. You can add/edit snippets by Tools->General Tools->Snippet Editor…
Ctrl+J = Activating TypeExplorer window. It helps to find the class by the first letters of class name. You can open the class at once.
F5, Ctrl+Enter = Compile project

Ctrl+Shift+K = Insert color
Ctrl+Shift+I = Insert GUID.

Code navigation

F4 = Goto method/class/property declaration.
Shift+F4 = Come back from there


F12 = Goto Next error.
Shift+F12 = Goto Previous error.
Ctrl+[ = Goto next statement (declaration of variables or function, condition statements, new operator etc.)
Ctrl+] = Goto previous statement
Ctrl+Shift+F = Expand/collapse current line
Ctrl+Shift+A = Collapse all
Ctrl+Shift+E = Expand all
Ctrl+G = Goto line number…

Edit

Double click on word = word selection
Ctrl+U = converts selected word to uppercase
Ctrl+L = converts selected word to lowercase
Ctrl+right arrow = Goto next word
Ctrl+left arrow = Goto previous word
Ctrl+up arrow = Scroll up the window
Ctrl+down arrow = Scroll down the window
Ctrl+/ = Goto previous subword (separate word or subword starting with capital letter. For example, the subword “Count” in word “filesCount”)
Ctrl+\ = Goto next subword
Alt+Home = Goto real line start but not the first not-null symbol of the line like Home
 key.
Ctrl+Home= Goto file begin.
Ctrl+End = Goto file end.
Ctrl+D = Duplicate the line
Ctrl+T = switches the current an the previous lines
Ctrl+Shift+D = Deleted the current line
Ctrl+Q = comment line
Ctrl+Shift+Q = uncomment line

Search

Ctrl+F = Search window
Ctrl+H = Replace window
Ctrl+I = Replace in Files window

F3 = Goto next word usage
Shift+F3 = Goto previous word usage

Windows managements

Ctrl+S = Saves the Tab
Ctrl+Shift+S = Save as…
Ctrl+W = Close the current tab
Alt+F4 = close FlashDevelop
Ctrl+N = Opens new blank tab
Hold CTRL and pressing TAB several times = switching tabs in forward direction
Hold Ctrl+Shift and pressing TAB = switching tabs in backward direction
Ctrl+TAB = Goto last active tab
Ctrl+PgUP = Goto between tabs from right to left
Ctrl+PgDown = Goto between tabs from left to right
Alt+Shift+Enter = Go to fullscreen

We make our fortune and call it fate

flex自动排版

http://flexformatter.googlecode.com/svn/trunk/FlexFormatter/FlexPrettyPrintCommandUpdateSite

把plugins目录下最新的自动排版插件下载到flex的安装目录就可以了

]]>

AS3晃动效果

]]>

flex组件样式编辑器

http://blog.minidx.com/2008/07/29/1183.html

http://examples.adobe.com/flex2/consulting/styleexplorer/Flex2StyleExplorer.html?

]]>

Flex profiler 查内存泄漏

http://www.junliu.net/?p=112

]]>