grid doesn't listen to my slider
hey there![]()
i did a code that zooms in and out a casket grid with the help of a slider. the grid works perfect with
a ready-made slider, but not with my own one
and it has to work with the own slider...
what's wrong in my code? i think it's just a little thing that's not working, but i don't know what...![]()
the slider is convoluted like this: "sliderG" and subordinated "thumb" and "bahn"...so the thumb
should move in the x direction of "bahn"-values...and i put the slider at a position of (0|0)...
can anyone help me?
thanks!
here's my code:
var pattern:BitmapData = createPatternOffset( [0xFF0000, 0x00FF00, 0x0000FF] );
//var drawPattern:int = map(sliderG.x, sliderG.x, sliderG.x+sliderG.width, 0, 100);
// this is where the code of my slider starts
sliderG.thumb.addEventListener(Event.CHANGE, f);
sliderG.thumb.liveDragging = true;
sliderG.thumb.buttonMode = true;
sliderG.thumb.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownGHandler);
sliderG.thumb.addEventListener(MouseEvent.MOUSE_UP, mouseUpGHandler);
sliderG.thumb.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveGHandler);
function mouseDownGHandler(event:MouseEvent):void {
sliderG.thumb.startDrag(false, sliderG.bahn);
}
function mouseUpGHandler(event:MouseEvent):void {
sliderG.thumb.stopDrag();
}
function mouseMoveGHandler(event:MouseEvent):void {
var sliderMax:Number = 400;
var sliderMin:Number = 0;
function moveSlider(event:MouseEvent):void {
sliderG.thumb.x = Math.max( sliderMin, Math.min( sliderMax, mouseX) );
dispatchEvent(new Event(Event.CHANGED, true, true));
}
}
f();
// here is the code of the pixel grid
function f(e:Event=null):void
{
var sf:Number = 100 / sliderG.thumb.value;
graphics.clear();
drawPattern(graphics,100, 30, 300, 300, sf, sf, false);
}
function createPatternOffset(cols:Array, transparency:Boolean=false):BitmapData
{
var len:int = cols.length;
var bd:BitmapData = new BitmapData(len,len,transparency,0);
for (var y:int = 0; y<len; ++y)
{
for (var x:int = 0; x<len; ++x)
{
bd.setPixel32(x, y, cols[(x-y+len)%len] | (transparency? 0: 0xFF000000));
}
}
return bd;
}
function drawPattern(canvas:Graphics, x:Number, y:Number, width:Number, height:Number, scaleX:Number=1, scaleY:Number=1, smoothing:Boolean=false):void
{
canvas.beginBitmapFill(pattern, new Matrix(scaleX, 0, 0, scaleY, x, y), true, smoothing);
canvas.drawRect(x, y, width, height);
canvas.endFill();
}
//pixel grid end