How to get a DisplayObject from an ILayoutElement to apply a BlurFilter
This is my layout:
package layouts{
import mx.core.ILayoutElement;
import mx.core.IVisualElement;
import spark.layouts.supportClasses.LayoutBase;
import flash.geom.Point;
import flash.geom.Matrix3D;
import flash.geom.Vector3D;
import flash.display.DisplayObject;
import flash.geom.PerspectiveProjection;
import spark.filters.BlurFilter;
import flash.filters.BitmapFilterQuality;
public class CoverFlowLayout extends LayoutBase {
private var _index:uint = 0;
override public function updateDisplayList(width:Number, height:Number):void {
super.updateDisplayList(width, height);
if (target) {
var pproj:PerspectiveProjection = new PerspectiveProjection();
pproj.projectionCenter = new Point(width / 2, height / 2);
target.transform.perspectiveProjection = pproj;
var total:int = target.numElements;
var actual:int = Math.max(index, 0);
for (var i:int = 0; i < total; i++) {
var element:ILayoutElement = (useVirtualLayout) ? target.getVirtualElementAt(i) : target.getElementAt(i);
var child:DisplayObject = target.getChildAt(i);
element.setLayoutBoundsSize(NaN, NaN, false);
var matrix:Matrix3D = new Matrix3D();
var offset:int = i - actual;
var rotation:Number = -12 * offset;
开发者_开发技巧 offset = Math.abs(offset);
var x:int = 190 * (i - actual) + width / 2;
var y:int = 0;
var blur:BlurFilter = new BlurFilter(offset, offset, BitmapFilterQuality.MEDIUM);
matrix.appendRotation(rotation, Vector3D.Y_AXIS);
matrix.appendTranslation(x, 0, 200 * offset);
IVisualElement(element).depth = total - offset;
child.filters = [blur];
element.setLayoutMatrix3D(matrix, false);
}
}
}
protected function invalidateTarget():void {
if(target) {
target.invalidateSize();
target.invalidateDisplayList();
}
}
[Bindable]
public function get index():uint {
return _index;
}
public function set index(value:uint):void {
if ( _index != value ) {
_index = value;
invalidateTarget();
}
}
}
}
but it seems that child and element doesn't match, so how can I apply that blur to the DisplayObject associated to the current element ILayoutElement within the loop?
Ok... maybe is this the way?:
DisplayObject(element).filters = [blur];
Is Flex 4 community dead or am I bad asking, tagging, etc?, lets answer my own question:
package layouts {
import mx.core.ILayoutElement;
import mx.core.IVisualElement;
import spark.layouts.supportClasses.LayoutBase;
import flash.geom.Point;
import flash.geom.Matrix3D;
import flash.geom.Vector3D;
import flash.display.DisplayObject;
import flash.geom.PerspectiveProjection;
import spark.filters.BlurFilter;
import flash.filters.BitmapFilterQuality;
public class CoverFlowLayout extends LayoutBase {
private var _index:uint = 0;
override public function updateDisplayList(width:Number, height:Number):void {
super.updateDisplayList(width, height);
if (target) {
var pproj:PerspectiveProjection = new PerspectiveProjection();
pproj.projectionCenter = new Point(width / 2, height / 2);
target.transform.perspectiveProjection = pproj;
var total:int = target.numElements;
var actual:int = Math.max(index, 0);
for (var i:int = 0; i < total; i++) {
var element:ILayoutElement = (useVirtualLayout) ? target.getVirtualElementAt(i) : target.getElementAt(i);
var child:DisplayObject = DisplayObject(element);
element.setLayoutBoundsSize(NaN, NaN, false);
var matrix:Matrix3D = new Matrix3D();
var offset:int = i - actual;
var rotation:Number = -12 * offset;
offset = Math.abs(offset);
var x:int = 190 * (i - actual) + width / 2;
var y:int = 0;
var blur:BlurFilter = new BlurFilter(offset, offset, BitmapFilterQuality.MEDIUM);
matrix.appendRotation(rotation, Vector3D.Y_AXIS);
matrix.appendTranslation(x, 0, 200 * offset);
IVisualElement(element).depth = total - offset;
child.filters = [blur];
element.setLayoutMatrix3D(matrix, false);
}
}
}
protected function invalidateTarget():void {
if(target) {
target.invalidateSize();
target.invalidateDisplayList();
}
}
[Bindable]
public function get index():uint {
return _index;
}
public function set index(value:uint):void {
if ( _index != value ) {
_index = value;
invalidateTarget();
}
}
}
}
精彩评论