Skip to main content
Known Participant
June 26, 2011
Question

grid doesn't listen to my slider

  • June 26, 2011
  • 1 reply
  • 826 views

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

This topic has been closed for replies.

1 reply

Inspiring
June 26, 2011

First, never use nested named functions. Fix that and see if it helps. moveSlider is nested inside mouseMoveGHandler.

TSIXDAuthor
Known Participant
June 26, 2011

thanks...but in line 54 there is still a mistake and i don't know what it is

function drawPattern(canvas:Graphics, x:Number, y:Number, width:Number, height:Number, scaleX:Number=1, scaleY:Number=1, smoothing:Boolean=false):void

and flash seems also to get some problems with the CHANGE event:

function drawPattern(canvas:Graphics, x:Number, y:Number, width:Number, height:Number, scaleX:Number=1, scaleY:Number=1, smoothing:Boolean=false):void

i only want to change the grid by moving the slider with my ready made slider it worked*grml* but i have to use my own one....

Inspiring
June 26, 2011

Did you fix nested function(s)?

What do you mean by "mistake"? Do you see error? If so - post full stack.