Hi.
I have successfully applied a drop shadow to a canvas with actionScript in a
<mx:Script> tag block. However I want to keep the actionScript external to the
MXML code. I have tried importing the drop shadow as code as shown below but I
cant get the drop shadow to appear. If I include 'this.backgroundCanvas.filters
= filters; in AddDropShadow.as as shown in the attached code I get the
following error:
1042: The this keyword can not be used in static methods. It can only be used
in instance methods, function closures, and global
code. PlayAIR/src/actionscript/com/barrygee/UI AddDropShadow.as line
24 1225277979009 855
If i leave that line so that it only has filters = filters; no drop shadow
appears.
any help very welcome.
Thanks
Barry.
MXML
-----------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
showFlexChrome="false"
creationComplete="init()">
<mx:Script>
<![CDATA[
import actionscript.com.barrygee.UI.AddDropShadow;
public function init():void
{
AddDropShadow.addShadow();
}
]]>
</mx:Script>
<mx:Canvas
id="backgroundCanvas"
left="5"
right="5"
top="5"
bottom="5"
backgroundColor="#000000"
backgroundAlpha="0.9"
cornerRadius="10"
alpha="1.0"
borderStyle="solid"
borderThickness="0"
mouseDown="nativeWindow.startMove()"/>
</mx:WindowedApplication>
AddDropShadow.as
-----------------------------------------------
package actionscript.com.barrygee.UI
{
import flash.filters.DropShadowFilter;
public class AddDropShadow
{
public function AddDropShadow():void
{
super();
}
public static function addShadow():void
{
var filters:Array = new Array();
var dFilter

ropShadowFilter = new DropShadowFilter();
dFilter.angle = 0;
dFilter.alpha = 0.5;
dFilter.blurX = 5;
dFilter.blurY = 5;
dFilter.distance = 0;
dFilter.strength = 2;
dFilter.quality = 3;
filters.push(dFilter);
this.backgroundCanvas.filters = filters;
}
}
}
This works
// With as in script block
----------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
showFlexChrome="false"
creationComplete="init()">
<mx:Script>
<
ropShadowFilter = new DropShadowFilter();
dFilter.angle = 0;
dFilter.alpha = 0.5;
dFilter.blurX = 5;
dFilter.blurY = 5;
dFilter.distance = 0;
dFilter.strength = 2;
dFilter.quality = 3;
filters.push(dFilter);
this.backgroundCanvas.filters = filters;
}
]]>
</mx:Script>
<mx:Canvas
id="backgroundCanvas"
left="5"
right="5"
top="5"
bottom="5"
backgroundColor="#000000"
backgroundAlpha="0.9"
cornerRadius="10"
alpha="1.0"
borderStyle="solid"
borderThickness="0"
mouseDown="nativeWindow.startMove()"/>
</mx:WindowedApplication>