[ActionScript 3.0] 创建倒影

package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.GradientType;
import flash.display.Loader;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.net.URLRequest; /**
* ...
* @author Frost.Yen
*/
[SWF(width=800, height=1000, backgroundColor=0x000000, frameRate=30)]
public class Reflection extends Sprite
{
private var ldr:Loader=new Loader();
private var pic:Sprite=new Sprite();
public function Reflection()
{
ldr.load(new URLRequest("http://hiphotos.baidu.com/frostyen/pic/item/7e49d8b53f6b48ffd9335aa2.jpg"));
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
} private function onImageLoaded(e:Event):void
{
this.addChild(pic);
pic.addChild(ldr);
pic.x = 200;
pic.y = 10;
ldr.scaleX = ldr.scaleY = .5;
createRef(pic,5,0);
}
/**
*
* @param obj 需创建倒影的对象
* @param distance 对象与倒影的距离
* @param offset 倒影的偏移量
*/
private function createRef(obj:DisplayObject,distance:Number=5,offset:Number=0):void
{
// 倒置
var bd:BitmapData = new BitmapData(obj.width,obj.height,true);
var mtx:Matrix = new Matrix();
mtx.d = -1;
mtx.ty = bd.height;
bd.draw(obj, mtx); // 添加倒影渐变
var _width:int = bd.width;
var _height:int = bd.height; mtx.createGradientBox(_width, _height, 0.5 * Math.PI,0,offset );
var shape:Shape = new Shape();
shape.graphics.beginGradientFill(GradientType.LINEAR, [0,0,0], [0.6,0.1, 0], [0,200, 255], mtx);
shape.graphics.drawRect(0, 0, _width, _height);
shape.graphics.endFill();
var mask_bd:BitmapData = new BitmapData(_width,_height,true,0);
mask_bd.draw(shape);
// 生成最终效果
bd.copyPixels(bd, bd.rect, new Point(0, 0), mask_bd, new Point(0, 0), false);
// 将倒影放置于对象下方
var ref:Bitmap = new Bitmap(bd);
ref.y = obj.height + obj.y + distance;
ref.x = obj.x;
obj.parent.addChild(ref);
}
} }
[ActionScript 3.0] 创建倒影的更多相关文章
- ActionScript 3.0入门:Hello World、文件读写、数据存储(SharedObject)、与JS互调
近期项目中可能要用到Flash存取数据,并与JS互调,所以就看了一下ActionScript 3.0,现把学习结果分享一下,希望对新手有帮助. 目录 ActionScript 3.0简介 Hello ...
- [转]ActionScript 3.0入门:Hello World、文件读写、数据存储(SharedObject)、与JS互调
本文转自:http://www.cnblogs.com/artwl/p/3396330.html 近期项目中可能要用到Flash存取数据,并与JS互调,所以就看了一下ActionScript 3.0, ...
- [ActionScript 3.0] AS3.0 动态加载显示内容
可以将下列任何外部显示资源加载到 ActionScript 3.0 应用程序中: 在 ActionScript 3.0 中创作的 SWF 文件 — 此文件可以是 Sprite.MovieClip 或扩 ...
- ActionScript 3.0 API 中的 Video 类
注:这个类在Flash流媒体开发中使用的很频繁,在此记录一下它的使用方法. 包 flash.media 类 public class Video 继承 Video DisplayObject Ev ...
- .NET微信公众号开发-2.0创建自定义菜单
一.前言 开发之前,我们需要阅读官方的接口说明文档,不得不吐槽一下,微信的这个官方文档真的很烂,但是,为了开发我们需要的功能,我们也不得不去看这些文档. 接口文档地址:http://mp.weixin ...
- ActionScript 3.0 for the Lunder Algorithm
package com.feiruo.Calendar.LunderCalendar { /* *@ClassName: package:com.feiruo.Calendar.LunderCalen ...
- cocos2d-x 3.0 创建工程的模板
将下面的代码拷贝到文本文件中,重命名文件为 cocos3.0创建工程.bat @echo off echo -------------------------create project with p ...
- 【转】学习Flex ActionScript 3.0 强烈推荐电子书
学习Flex ActionScript 3.0 强烈推荐电子书 AdvancED ActionScript 3.0 Animation(<Make things move>姐妹篇,强烈推 ...
- android 5.0 创建多用户 双开多开应用(2)
上一讲 讲了如何创建一个user android 5.0 创建多用户 双开多开应用(1) 为什么要创建User 例如window 系统创建了一个user 会在当前用户下进行操作,而android 多 ...
随机推荐
- java 蓝桥杯基础练习 01字串 进制转换
问题描述 对于长度为5位的一个01串,每一位都可能是0或1,一共有32种可能.它们的前几个是: 请按从小到大的顺序输出这32种01串. 输入格式 本试题没有输入. 输出格式 输出32行,按从小到大的顺 ...
- SMTPSenderRefused: (530, ‘5.5.1 Authentication Required. Learn more at \n5.5.1
在跟着<Flask Web开发:基于Python的Web应用开发实战>一书学习时,出现了以上错误提示. 问题出于第11章--博客文章.当运行 python manage.py runser ...
- Python基础:Python数据类型及逻辑判断语句
Python代码需要严谨的缩进 # 导包 import random # ********************输入输出***************** # 输出 print("hell ...
- ubuntu18 tensorflow faster_rcnn cpu训练自己数据集
(flappbird) luo@luo-ThinkPad-W540:tf-faster-rcnn$ ./experiments/scripts/train_faster_rcnn.sh 0 pasca ...
- code1154 能量项链
d[l][i]表示:从第i个珠子开始,连续l个珠子合并后释放的最大能量 状态转移方程d[l][i] = d[j][i] + d[l-j][i+j] + w[i]*w[i+j]*w[i+l],j从1到l ...
- python3--json反序列化
# Auther: Aaron Fan # 加载文件中的数据 import json with open('test.txt','r',encoding='utf-8') as f: info = j ...
- 斐波那契数列—java实现
最近在面试的时候被问到了斐波那契数列,而且有不同的实现方式,就在这里记录一下. 定义 斐波那契数列指的是这样一个数列 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
- app里面嵌套的H5页面上电话号码怎么才能点击拨号?
代码: <p>联系我们:<a href="tel://66666666666">66666666666</a> </p>
- CodeForces 289A Polo the Penguin and Segments (水题)
题意:给你 n 段区间,而且还是不相交的,然后你只能向左扩展左端点,或者向右扩展右端点,然后扩展最少的步数让整数总数能够整除 k. 析:很简单么,只要在记录算一下数量,然后再算出 k 的倍数差多少就行 ...
- UVa 12342 Tax Calculator (水题,纳税)
今天在uva看到一个水题,分享一下. 题意:制定纳税的总额,有几个要求,如果第一个180000,不纳,下一个300000,纳10%,再一个400000,纳15%,再一个300000,纳20%,以后的纳 ...