<canvas x="0" y="0" width="598" height="503" alpha="0.5" backgroundimage="myImage.jpg" id="myCanvas" backgroundcolor="#FFFFFF" horizontalscrollpolicy="off" verticalscrollpolicy="off"><br> </canvas>
Once the Flex application was ready I added an ActionScript class file to the project called "MyClass.as" with the following code:
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.net.URLRequest;
public class MyClass extends Sprite
{
public function MyClass():void
{
var loader:Loader = new Loader();
var url:URLRequest = new URLRequest("myImage.jpg");
loader.load(url);
this.addChild(loader);
var circle:Sprite = new Sprite();
circle.graphics.beginFill(0x00FFFFFF, 1.0);
circle.graphics.drawCircle(0, 0, 50);
circle.graphics.endFill();
this.addChild(circle);
loader.cacheAsBitmap = true;
circle.cacheAsBitmap = true;
loader.mask = circle;
circle.startDrag(true);
}
}
}
Of course for the "myImage.jpg" you will need to substitute some sort of image of your own and bring it into your project for the spotlight effect to work. Adjust the sizes as determined by your image size and needs. Its goes without saying that there are better spots to put this code other than the class's constructor but since this is just a simple example I wanted to keep everything as simple as possible. 当然你可以替换自己的图片将代码整合到自己的项目中去
Run the project and simply click on the rendered SWF in your web browser and you should see the spotlight effect following your mouse around. 运行代码测试一下
本文转自
http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&productId=2&postId=6842
本文介绍如何在Flex应用程序中实现Spotlight效果。通过创建ActionScript类并利用Loader加载图像,结合Sprite绘制圆形遮罩,使鼠标移动时产生跟随的高亮效果。
9668

被折叠的 条评论
为什么被折叠?



