|
-
[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
-
newb of many sorts
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:uint; iKNOB< KNOBarray.length; iKNOB++) { //accessing the knob directly, rather than using getChildByName var KNOB:MovieClip = KNOBarray[iKNOB]; KNOB.buttonMode = true; KNOB.addEventListener(MouseEvent.MOUSE_DOWN, knobPRESS); 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_MOVE, knobMOVE); stage.addEventListener(MouseEvent.MOUSE_UP, knobRELEASE); }
That should do it. Let me know if it works out.
Search first, asked questions later.
-
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.
-
newb of many sorts
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.
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|