Copy link to clipboard
Copied
Hey everyone,
I'm trying to use a slider's position to control values in this code:
video.filters = [MatrixUtil.setBrightness(sliderAValue),
MatrixUtil.setContrast(sliderBValue),
MatrixUtil.setSaturation(sliderCValue)];
The code above resides within a Movie Clip, but I want the sliders in the main scene. They don't have to be custom. I'm fine using the sliders in Flash's library. It seems OOP is the way to go, but I don't know much about it right now. If anyone could explain this to me in detail, I would greatly appreciate it.
Thanks.
that's not good coding because you're unnecessarily using system resources in an endless enterframe loop for something that can be done much more efficiently.
in addition, it won't work.
if you use a slider component you can use a change event. if that's your custom slider you can probably use a mouseup event:
mySlider.sliderKnob.addEventListener(MouseEvent.MOUSE_UP,sliderchangeF);
function sliderchangeF(e:MouseEvent):void{
theinstancenameofyourfiltercontainingmovieclip.changeFilterF(mySlider.slider
...Copy link to clipboard
Copied
does the movieclip that contains that code lie on the main timeline?
if so, you can use parent.sliderAValue to reference sliderAValue on the main timeline. likewise with the other values.
Copy link to clipboard
Copied
No. All of the Movie Clip's code is contained within itself. There is no Actionscript on the main timeline.
Copy link to clipboard
Copied
is that movieclip on the main timeline?
Copy link to clipboard
Copied
Yep!
Copy link to clipboard
Copied
then use the code i suggested.
Copy link to clipboard
Copied
Ohhh I see. I misunderstood the first time I read it. If I use that, I get a 1119 error. "Access of possibly undefined property sliderValue through a reference with static type flash.display:DisplayObjectContainer"
Any ideas?
EDIT:
I just used
video.filters = [MatrixUtil.setBrightness(MovieClip(parent).sliderValue),
MatrixUtil.setContrast(0),
MatrixUtil.setSaturation(0)];
and got no errors. The only problem is, the slider doesn't change the value of brightness at all. I tested the slider with a dynamic text box, so I know the value changes.
Copy link to clipboard
Copied
does that code execute AFTER sliderValue changes?
Copy link to clipboard
Copied
I don't know the order of execution, but I tried moving that piece of code around a lot, and it always resulted in whatever the initial values were. I'm trying to apply these changes to a live video feed from my camera.
Copy link to clipboard
Copied
use the trace function to debug your logic: Debugging ActionScript That Triggers No Errors | Adobe Community
but almost certainly you're not executing the filter code at the correct time. that code should be in a function and that function should be called when you detect a slider change and sliderValue changes.
Copy link to clipboard
Copied
Okay, I understand what you're saying about creating and calling a function. The code just takes the first value and never updates on an event change; in this case, the slider value changing. Is the goal to turn
video.filters = [MatrixUtil.setBrightness(MovieClip(parent).sliderValue),
MatrixUtil.setContrast(0),
MatrixUtil.setSaturation(0)];
into a function? I don't really know how to go about doing that... Maybe I'm in over my head. Did I mention I don't have much ActionScript experience?
Copy link to clipboard
Copied
use:
function changeFilterF():void{
video.filters = [MatrixUtil.setBrightness(MovieClip(parent).sliderValue),
MatrixUtil.setContrast(0),
MatrixUtil.setSaturation(0)];
}
then call that function from that parent movieclip when your slider changes. if you don't know how to do that, what code are you currently using to update sliderValue?
Copy link to clipboard
Copied
Ahh okay. I was on the right track then. I had that same code (with a different function name) but didn't realize I had to call it in the movie clip. I have this code on the main timeline to get the value of one slider.
import flash.events.Event;
// Enter Frame Event
var sliderValue:uint = mySlider.sliderKnob.x;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void {
sliderValue = mySlider.sliderKnob.x;
status_txt.text = "pos is" + sliderValue;
MovieClip(parent).changeFilterF(sliderValue); //I JUST ADDED THIS
}
I haven't debugged yet, but I'll let you know how it goes.
Copy link to clipboard
Copied
that's not good coding because you're unnecessarily using system resources in an endless enterframe loop for something that can be done much more efficiently.
in addition, it won't work.
if you use a slider component you can use a change event. if that's your custom slider you can probably use a mouseup event:
mySlider.sliderKnob.addEventListener(MouseEvent.MOUSE_UP,sliderchangeF);
function sliderchangeF(e:MouseEvent):void{
theinstancenameofyourfiltercontainingmovieclip.changeFilterF(mySlider.sliderKnob.x);
}
and change changeFilterF to
function changeFilterF(sliderValue):void{
video.filters = [MatrixUtil.setBrightness(sliderValue),
MatrixUtil.setContrast(0),
MatrixUtil.setSaturation(0)];
}
Copy link to clipboard
Copied
Awesome! It worked the first time! I really appreciate all the help.
Thanks a lot,
Eric
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now