我需要一些帮助。
我有一个类文件,我已导入它,如下图所示:
该文件的代码是:
package
{
import flash.display.Sprite;
import fl.motion.AdjustColor;
import flash.filters.ColorMatrixFilter;
import fl.events.SliderEvent;
public class Main extends Sprite
{
private var color:AdjustColor = new AdjustColor();
private var filter:ColorMatrixFilter;
public function Main():void
{
/* Required to create initial Matrix */
color.brightness = 0;
color.contrast = 0;
color.hue = 0;
color.saturation = 0;
/* Add Listeners function */
addListeners();
}
private final function addListeners():void
{
colorPanel.brightSL.addEventListener(SliderEvent.CHANGE, adjustBrightness);
colorPanel.contSL.addEventListener(SliderEvent.CHANGE, adjustContrast);
colorPanel.hueSL.addEventListener(SliderEvent.CHANGE, adjustHue);
colorPanel.satSL.addEventListener(SliderEvent.CHANGE, adjustSaturation);
}
private final function adjustBrightness(e:SliderEvent):void
{
color.brightness = e.target.value;
update();
}
private final function adjustContrast(e:SliderEvent):void
{
color.contrast = e.target.value;
update();
}
private final function adjustHue(e:SliderEvent):void
{
color.hue = e.target.value;
update();
}
private final function adjustSaturation(e:SliderEvent):void
{
color.saturation = e.target.value;
update();
}
private final function update():void
{
filter = new ColorMatrixFilter(color.CalculateFinalFlatArray());
image.filters = [filter];
}
}
}
现在我想从时间轴导入此文件。可能吗; 我从文档属性中删除类名,并从时间轴(frame1)导入它,如:import Main
什么都没发生。
谢谢!
答案 0 :(得分:0)
我认为你做的更好的方法就是这样......
以下是一个示例:http://dopserv1.dop.com/ColorMatrixExample.swf
现在解释;在你的FLA中:
import Main;
var main:Main = new Main();
addChild(main);
你的Main.as课程将是:
package
{
import flash.display.Sprite;
import fl.motion.AdjustColor;
import flash.filters.ColorMatrixFilter;
import fl.events.SliderEvent;
import flash.events.Event;
public class Main extends Sprite
{
private var color:AdjustColor = new AdjustColor();
private var filter:ColorMatrixFilter;
private var panel:ColorPanel;
private var image:Image;
public function Main():void
{
/* Required to create initial Matrix */
color.brightness = 0;
color.contrast = 0;
color.hue = 0;
color.saturation = 0;
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
panel = new ColorPanel();
panel.x = 15;
panel.y = 15;
addChild(panel);
image = new Image();
image.x = 150;
image.y = 150;
addChild(image);
panel.brightSL.addEventListener(SliderEvent.THUMB_DRAG, adjustBrightness);
panel.contSL.addEventListener(SliderEvent.THUMB_DRAG, adjustContrast);
panel.hueSL.addEventListener(SliderEvent.THUMB_DRAG, adjustHue);
panel.satSL.addEventListener(SliderEvent.THUMB_DRAG, adjustSaturation);
}
private function adjustBrightness(e:SliderEvent):void
{
color.brightness = e.target.value;
update();
}
private function adjustContrast(e:SliderEvent):void
{
color.contrast = e.target.value;
update();
}
private function adjustHue(e:SliderEvent):void
{
color.hue = e.target.value;
update();
}
private function adjustSaturation(e:SliderEvent):void
{
color.saturation = e.target.value;
update();
}
private function update():void
{
filter = new ColorMatrixFilter(color.CalculateFinalFlatArray());
image.filters = [filter];
}
}
}
现在在我的FLA库中,我只是导入了一个图像,从中制作了一个影片剪辑,并为其指定了Image
的链接名称。一旦创建,就从舞台上删除它。
然后对于你的colorPanel
,我将4个幻灯片放到舞台上,根据你班级中的名字命名它们,并用实例名ColorPanel
创建一个影片剪辑。一旦创建,就从舞台上删除它。
另请注意:我将SliderEvent.CHANGE更改为SliderEvent.THUMB_DRAG,因为我希望这更像是您要查找的结果。