Flash 未在页面上加载反射位图

Flash 未在页面上加载反射位图,flash,actionscript-3,Flash,Actionscript 3,我在精灵中加载了一个图像,该图像来自远程位置“http://i.ytimg.com/vi/yre5nBXAxyk/0.jpg". 一旦图像加载到加载程序对象中,我就想创建包含图像的精灵的反射。现在,当我在FlashIDE中运行应用程序时,这一点就起作用了,但是当我将这个flash应用程序嵌入HTML页面时,反射图像就不起作用了。为什么会这样,代码如下 //////////////////////////////////////////// //项目:Flash 10 Coverflow //日

我在精灵中加载了一个图像,该图像来自远程位置“http://i.ytimg.com/vi/yre5nBXAxyk/0.jpg". 一旦图像加载到加载程序对象中,我就想创建包含图像的精灵的反射。现在,当我在FlashIDE中运行应用程序时,这一点就起作用了,但是当我将这个flash应用程序嵌入HTML页面时,反射图像就不起作用了。为什么会这样,代码如下

////////////////////////////////////////////
//项目:Flash 10 Coverflow //日期:10/3/09 //作者:斯蒂芬·韦伯 //////////////////////////////////////////// 包装{

////////////////////////////////////////////
// IMPORTS
////////////////////////////////////////////
import flash.system.Security;

import flash.external.ExternalInterface;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Matrix;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.utils.setInterval;
import flash.utils.clearInterval;

public class Reflect extends MovieClip {
    ////////////////////////////////////////////
    // VARIABLES
    ////////////////////////////////////////////

    //reference to the movie clip we are reflecting
    private var _reflectionSprite:Sprite;

    //the BitmapData object that will hold a visual copy of the mc
    private var _bitmapData:BitmapData;

    //the BitmapData object that will hold the reflected image
    private var _reflectionBitmap:Bitmap;

    //the clip that will act as out gradient mask
    private var _gradientMask:MovieClip;

    //how often the reflection should update (if it is video or animated)
    private var _updateTime:Number;

    //the size the reflection is allowed to reflect within
    private var _bounds:Object;

    //the distance the reflection is vertically from the mc
    private var _distance:Number=0;

    function Reflect(args:Object) {


        _reflectionSprite=args.target;

        //the alpha level of the reflection clip
        var alpha:Number=args.alpha/100;

        //the ratio opaque color used in the gradient mask
        var ratio:Number=args.ratio;

        //update time interval
        var _updateTime:Number=args._updateTime;

        //the distance at which the reflection visually drops off at
        var reflectionDropoff:Number=args.reflectionDropoff;

        //the distance the reflection starts from the bottom of the mc
        var _distance:Number=args.distance;

        //store width and height of the clip
        var spriteHeight=_reflectionSprite.height;
        var spriteWidth=_reflectionSprite.width;

        //store the _bounds of the reflection
        _bounds = new Object();
        _bounds.width=spriteWidth;
        _bounds.height=spriteHeight;
        if (_bounds.width>0) {
            //create the BitmapData that will hold a snapshot of the movie clip
            _bitmapData=new BitmapData(_bounds.width,_bounds.height,true,0xFFFFFF);
            _bitmapData.draw(_reflectionSprite);

            //create the BitmapData the will hold the reflection
            _reflectionBitmap=new Bitmap(_bitmapData);
            //flip the reflection upside down
            _reflectionBitmap.scaleY=-1;
            //move the reflection to the bottom of the movie clip
            _reflectionBitmap.y = (_bounds.height*2) + _distance;
            _reflectionSprite.visible = true;
            //add the reflection to the movie clip's Display Stack
            var _reflectionBitmapRef:DisplayObject=_reflectionSprite.addChild(_reflectionBitmap);
            _reflectionBitmapRef.name="_reflectionBitmap";

            //add a blank movie clip to hold our gradient mask
            var gradientMaskRef:DisplayObject = _reflectionSprite.addChild(new MovieClip());
            gradientMaskRef.name="_gradientMask";

            //get a reference to the movie clip - cast the DisplayObject that is returned as a MovieClip
            _gradientMask=_reflectionSprite.getChildByName("_gradientMask") as MovieClip;
            //set the values for the gradient fill
            var fillType:String=GradientType.LINEAR;
            var colors:Array=[0xFFFFFF,0xFFFFFF];
            var alphas:Array=[alpha,0];
            var ratios:Array=[0,ratio];
            var spreadMethod:String=SpreadMethod.PAD;
            //create the Matrix and create the gradient box
            var matr:Matrix = new Matrix();
            //set the height of the Matrix used for the gradient mask
            var matrixHeight:Number;
            if (reflectionDropoff<=0) {
                matrixHeight=_bounds.height;
            } else {
                matrixHeight=_bounds.height/reflectionDropoff;
            }
            matr.createGradientBox(_bounds.width, matrixHeight, (90/180)*Math.PI, 0, 0);
            //create the gradient fill
            _gradientMask.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);
            _gradientMask.graphics.drawRect(0,0,_bounds.width,_bounds.height);
            //position the mask over the reflection clip
            _gradientMask.y=_reflectionSprite.getChildByName("_reflectionBitmap").y-_reflectionSprite.getChildByName("_reflectionBitmap").height;
            //cache clip as a bitmap so that the gradient mask will function
            _gradientMask.cacheAsBitmap=true;
            _reflectionSprite.getChildByName("_reflectionBitmap").cacheAsBitmap=true;
            //set the mask for the reflection as the gradient mask
            _reflectionSprite.getChildByName("_reflectionBitmap").mask=_gradientMask;

            //if we are updating the reflection for a video or animation do so here
            if (_updateTime>-1) {
                _updateTime=setInterval(update,_updateTime,_reflectionSprite);
            }
        }
    }


    public function setBounds(w:Number,h:Number):void {
        //allows the user to set the area that the reflection is allowed
        //this is useful for clips that move within themselves
        _bounds.width=w;
        _bounds.height=h;
        _gradientMask.width=_bounds.width;
        redrawBMP(_reflectionSprite);
    }
    public function redrawBMP(_target:Sprite):void {
        // redraws the bitmap reflection - Mim Gamiet [2006]
        _bitmapData.dispose();
        _bitmapData=new BitmapData(_bounds.width,_bounds.height,true,0xFFFFFF);
        _bitmapData.draw(_target);
    }
    private function update(_target:Sprite):void {
        //updates the reflection to visually match the movie clip
        _bitmapData=new BitmapData(_bounds.width,_bounds.height,true,0xFFFFFF);
        _bitmapData.draw(_target);
        _reflectionBitmap.bitmapData=_bitmapData;
    }
    public function destroy():void {
        //provides a method to remove the reflection
        _reflectionSprite.removeChild(_reflectionSprite.getChildByName("_reflectionBitmap"));
        _reflectionBitmap=null;
        _bitmapData.dispose();
        clearInterval(_updateTime);
        _reflectionSprite.removeChild(_reflectionSprite.getChildByName("_gradientMask"));
    }
}
////////////////////////////////////////////
//进口
////////////////////////////////////////////
导入flash.system.Security;
导入flash.external.ExternalInterface;
导入flash.display.MovieClip;
导入flash.display.Sprite;
导入flash.display.DisplayObject;
导入flash.display.BitmapData;
导入flash.display.Bitmap;
导入flash.geom.Matrix;
导入flash.display.GradientType;
导入flash.display.SpreadMethod;
导入flash.utils.setInterval;
导入flash.utils.clearInterval;
公共类电影{
////////////////////////////////////////////
//变数
////////////////////////////////////////////
//参考我们正在反映的电影剪辑
private var_reflectionSprite:Sprite;
//将保存mc的可视副本的BitmapData对象
私有变量bitmapData:bitmapData;
//将保存反射图像的BitmapData对象
私有变量反射位图:位图;
//将用作渐变外遮罩的剪辑
私有变量梯度掩码:MovieClip;
//反射更新的频率(如果是视频或动画)
私有变量更新时间:Number;
//允许反射的大小
私有变量界:对象;
//反射与mc垂直的距离
私有变量距离:数字=0;
函数反射(参数:对象){
_reflectionSprite=args.target;
//反射剪辑的alpha级别
var alpha:Number=args.alpha/100;
//渐变遮罩中使用的不透明颜色比率
var比率:数字=参数比率;
//更新时间间隔
var\u updateTime:Number=args.\u updateTime;
//反射在某个位置视觉上消失的距离
var reflectionDropoff:Number=args.reflectionDropoff;
//反射从mc底部开始的距离
var_距离:Number=args.distance;
//存储剪辑的宽度和高度
var spriteHeight=_reflectionSprite.height;
var spriteWidth=_reflectionSprite.width;
//存储反射的_边界
_边界=新对象();
_宽度=精灵宽度;
_边界高度=精灵高度;
如果(_bounds.width>0){
//创建将保存电影剪辑快照的位图数据
_bitmapData=新的bitmapData(_-bounds.width,_-bounds.height,true,0xFFFFFF);
_bitmapData.draw(_reflectionSprite);
//创建将保存反射的位图数据
_reflectionBitmap=新位图(_bitmapData);
//把倒影翻转过来
_reflectionBitmap.scaleY=-1;
//将反射移动到电影剪辑的底部
_reflectionBitmap.y=(_bounds.height*2)+_distance;
_reflectionSprite.visible=true;
//将反射添加到电影剪辑的显示堆栈中
var\u reflectionBitmapRef:DisplayObject=\u reflectionSprite.addChild(\u reflectionBitmap);
_reflectionBitmapRef.name=“\u reflectionBitmap”;
//添加一个空白的电影剪辑来保存渐变遮罩
var gradientMaskRef:DisplayObject=_reflectionSprite.addChild(new MovieClip());
gradientMaskRef.name=“_gradientMask”;
//获取对电影剪辑的引用-播放作为MovieClip返回的DisplayObject
_gradientMask=\u reflectionSprite.getChildByName(“\u gradientMask”)作为MovieClip;
//设置渐变填充的值
var fillType:String=GradientType.LINEAR;
变量颜色:数组=[0xFFFFFF,0xFFFFFF];
var alphas:Array=[alpha,0];
var比率:数组=[0,比率];
var spreadMethod:String=spreadMethod.PAD;
//创建矩阵并创建渐变框
var matr:矩阵=新矩阵();
//设置用于渐变遮罩的矩阵的高度
var matrixHeight:数字;
if(reflectionDropoff-1){
_updateTime=setInterval(update,_updateTime,_reflectionSprite);
}
}
}
公共功能立根(w:编号,h:编号):无效{
//允许用户设置允许反射的区域
//这对于在其内部移动的剪辑非常有用
_宽度=w;
_高度=h;
_gradientMask.width=\u bounds.width;
重绘BMP(_reflectionSprite);
}
公共函数重画bmp(_目标:精灵):无效{
//重绘位图反射-Mim Gamiet[2006]
_dispose();
_bitmapData=新的bitmapData(_-bounds.width,_-bounds.height,true,0xFFFFFF);
_bitmapData.draw(_目标);
}
私有函数更新(_目标:Sprite):无效{
//更新反射以在视觉上匹配电影剪辑
_bitmapData=新的bitmapData(_-bounds.width,_-bounds.height,true,0xFFFFFF);
_bitmapData.draw(_目标);
_reflectionBitmap.bitmapData=\u bitmapData;
}
公共函数destroy():void{
//提供移除反射的方法
_reflectionSprite.removeChild(_reflectionSprite.getChildByName(“_reflectionBitmap”);
_reflectionBitmap=null;
_dispose();
clearInterval(_updateTime);
_reflectionSprite.removeChild(_reflectionSprite.getChildByName(_gradientMask));
}
}
<
var request:URLRequest = new URLRequest ();
request.url = "http://ServerB/images/foo.jpg";

//This is important step..

var loaderContext:LoaderContext = new LoaderContext ();
loaderContext.checkPolicyFile = true;

var loader:Loader = new Loader ();
loader.load (request, loaderContext);

//now you can draw.
var bitmapData:BitampData = new BitmapData (200, 200);
bitmapData.draw (loader);