A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: click-and-rotating knobs

  1. #1
    Senior Member
    Join Date
    Oct 2009
    Posts
    112

    [RESOLVED] click-and-rotating knobs

    I have an array of knobs, they all have functions so that you can click-and-drag left-right or up-down to make them rotate back and forth.
    when i have one knob on its own the code works fine. but now that i've put them in an arrary i've confused myself with the code.
    i have a var currentKnob:MovieClip
    and a var KNOB:MovieClip
    the reason i have a currentKnob var is so that when i'm tracing the click-on knob, as3 will know which one is being clicked.
    i've got confused on where i should include currentKnob in the functions, and where i should include KNOB in the functions.
    i think just by looking at the code someoen can probly figrue out where i mixed the two up, but i have tried lots of combinations mixing the two up and keep getting the same error:
    Code:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    	at knobs_fla::MainTimeline/frame1()

    thanks for any help
    Last edited by mattwatts15; 11-12-2009 at 03:57 PM. Reason: mark as resolved

  2. #2
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    well, right now you're declairing currentKnob, but nowhere to you reference it to an actual MovieClip. So when you call currentKnob.stop(), you're not pointing at anything, and it throws an error.

    Also, is there a reason you're using strings in your array? Here, try something like this...

    PHP Code:
    //currentKnob.stop();
    // removed quotes around knob names
    var KNOBarray:Array = new Array(gainKNOB,loKNOB,lomidKNOB,himidKNOB,hiKNOB);
    var 
    currentKnob:MovieClip;
    for (var 
    iKNOB:uintiKNOBKNOBarray.lengthiKNOB++) {
        
    //accessing the knob directly, rather than using getChildByName
        
    var KNOB:MovieClip KNOBarray[iKNOB];
           
    KNOB.buttonMode true;
        
    KNOB.addEventListener(MouseEvent.MOUSE_DOWNknobPRESS);
        
    KNOB.stop();
    }

    function 
    knobPRESS(evt:MouseEvent):void {
        
    // assign your currentKnob here
        
    currentKnob evt.target;
        
    startX KNOB.mouseX;
        
    startY KNOB.mouseY;
        
    startFrame KNOB.currentFrame;
        
    stage.addEventListener(MouseEvent.MOUSE_MOVEknobMOVE);
        
    stage.addEventListener(MouseEvent.MOUSE_UPknobRELEASE);

    That should do it. Let me know if it works out.
    Search first, asked questions later.

  3. #3
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    thanks when i got rid of the currentKnob.stop(); that got rid of the error.

    when i added:
    Code:
    function knobPRESS(evt:MouseEvent):void {
      currentKnob=evt.target;
      startX = currentKnob.mouseX;
      startY = currentKnob.mouseY;
      startFrame = currentKnob.currentFrame;
      stage.addEventListener(MouseEvent.MOUSE_MOVE, knobMOVE);
      stage.addEventListener(MouseEvent.MOUSE_UP, knobRELEASE);
    }
    i now get this error

    Code:
    1118: Implicit coercion of a value with static type Object to a possibly unrelated type flash.display:MovieClip.

  4. #4
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    nm, just realized this is marked as resolved
    Last edited by Ralgoth; 11-13-2009 at 08:45 AM. Reason: unnecessary
    Search first, asked questions later.

  5. #5
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    yea i figured out instead of
    Code:
    currentKnob=evt.target;
    it has to be
    Code:
    currentKnob=evt.target as MovieClip;
    thanks

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center