0
votes

I need some help please.

I have a class file and i have importing it as you can see from the image below:

enter image description here

And the code of this file is:

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];
        }






    }
}

Now i want to import this file from timeline. Is it possible; I i remove the class name from the document properties and import it from timeline (frame1) like: import Main

Nothing happens.

Thanks!

1
ok so you imported it. Are you making an instance of it? For example: var main:Main = new Main();Ronnie

1 Answers

0
votes

A better approach to what I believe you are doing would be something like this..

Here is an example: http://dopserv1.dop.com/ColorMatrixExample.swf

Now to explain; in your FLA:

import Main;

var main:Main = new Main();
addChild(main);

And you Main.as class will be:

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];
        }
    }
}

Now in my Library of the FLA, I simply imported an image, made a movie clip out of it and gave it a linkage name of Image. Delete it from the stage once its created.

Then for your colorPanel, I drug 4 sliders to the stage, named them according to the names in your class and created one movie clip out of them with an instance name of ColorPanel. Delete it from the stage once its created.

Also note: I changed your SliderEvent.CHANGE to SliderEvent.THUMB_DRAG as I would expect this is more of the result you are looking for.