A Flash Developer Resource Site

View Poll Results: Was this post clear and to the point?

Voters
1. You may not vote on this poll
  • Wait what? say that again....complete jibberish

    0 0%
  • i don't think u knwo what yoru talking about

    0 0%
  • you could clarify your post better

    1 100.00%
  • VERY CLEAR POST!

    0 0%
Multiple Choice Poll.
Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27

Thread: array and indexing movie clips

  1. #21
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Oh. yeah, there's a bug there. currentFader will be null until you actually drag one.
    Code:
    function loop(e:Event):void{	
       if (currentFader != null){
         var bounds:Rectangle = currentFader.bounds;
         svalue.text=String(Math.round((currentFader.y-bounds.bottom)/(bounds.top-bounds.bottom)*8.00));
       }
    }
    
    function dropScroll(evt:MouseEvent):void{
      currentFader.stopDrag();
      currentFader = null;
      dragging=false;
    }
    I'm sure it's called loop because it runs every frame. You do need a separate bounds for each fader, but I've already done that above and set each as a property on their respective faders.

    What error exactly did you get when trying to put the clips in the array directly?
    Last edited by 5TonsOfFlax; 11-10-2009 at 06:00 PM.

  2. #22
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    Quote Originally Posted by 5TonsOfFlax View Post
    Oh. yeah, there's a bug there. currentFader will be null until you actually drag one.
    Code:
    function loop(e:Event):void{	
       if (currentFader != null){
         var bounds:Rectangle = currentFader.bounds;
         svalue.text=String(Math.round((currentFader.y-bounds.bottom)/(bounds.top-bounds.bottom)*8.00));
       }
    }
    
    function dropScroll(evt:MouseEvent):void{
      currentFader.stopDrag();
      currentFader = null;
      dragging=false;
    }
    I'm sure it's called loop because it runs every frame. You do need a separate bounds for each fader, but I've already done that above and set each as a property on their respective faders.

    What error exactly did you get when trying to put the clips in the array directly?
    oh ok that makes sense. so that error still comes up but everything works. im guessing thats ok? is there a way to do it without that error still coming up or should i jsut ignore it?
    and seriously where did u learn as3, how do u knwo everything?

    andn this is the error i got when i left out the quotes:

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at D3264NEW_fla::MainTimeline/frame1
    Last edited by mattwatts15; 11-10-2009 at 06:08 PM.

  3. #23
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    What error are you talking about now? The last code I posted should have fixed the 1009 null error. You shouldn't ignore errors, they mean something's wrong. At the very least, use a try/catch so that the error doesn't show at runtime (don't do that here).

    I taught myself AS3 by just exploring and trying to build fun stuff. I already knew several programming languages through school and jobs, though.

    edit: whoops. same error in dropScroll if currentFader was never set:
    Code:
    function dropScroll(evt:MouseEvent):void{
      if (currentFader != null){
        currentFader.stopDrag();
        currentFader = null;
      }
      dragging=false;
    }

  4. #24
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    thats cool, u can answer all my quesitons its crazy.

    im not sure why im still getting that error..i think i need to go through and clean up the code becaus i've now editited it alot and its got a bit jumbled up so ill let u know if i cant fix it.

    and im not sure if u saw i edited my last post,
    the error i got when i remove the quotes is this:

    Code:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    	at D32NEW_fla::MainTimeline/frame1()
    or similar to that at least

  5. #25
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    That's weird. It looks like the fader variables are not initialized yet because they are not on stage, but if that's the case, then I would have expected the getChildByName to fail as well.

    Oh well. Looks like you have a workaround for that particular issue.

  6. #26
    Senior Member
    Join Date
    Oct 2009
    Posts
    112
    ok the error isnt still coming from the loop function, your right your code did fix that, its coming form a different part of my code.

    my questions is, in the for loop, how do you know which addEventListeners to put in there, and which ones to leave out

    heres my code now.........
    Code:
    var FADERarray:Array=new Array("fader1","fader2","fader3","fader4","fader5");
    var currentFader:MovieClip;
    var draging:Boolean=false;
    addEventListener(Event.ENTER_FRAME, loop);
    for (var iFADER:uint; iFADER< FADERarray.length; iFADER++) {
        var FADER:MovieClip=getChildByName(FADERarray[iFADER]) as MovieClip;
        FADER.addEventListener(MouseEvent.MOUSE_DOWN, dragScroll);
        addEventListener(MouseEvent.MOUSE_MOVE, moveScroll);
    	stage.addEventListener(MouseEvent.MOUSE_UP, dropScroll);
    	FADER.bounds = new Rectangle(FADER.x,795,0,205); //works because it's a dynamic class.  otherwise declare this property.
    	FADER.buttonMode = true;	
    }
    
    function dragScroll(evt:MouseEvent):void{
      currentFader = MovieClip(evt.currentTarget);
      currentFader.startDrag(false,currentFader.bounds);
      draging=true;
    }
    
    function loop(e:Event):void{	
       if (currentFader != null){
         var bounds:Rectangle = currentFader.bounds;
         svalue.text=String(Math.round((currentFader.y-bounds.bottom)/(bounds.top-bounds.bottom)*8.00));
       }
    }
    
    function dropScroll(evt:MouseEvent):void{
      currentFader.stopDrag();
      currentFader = null;
      draging=false;
    }
    
    
    
    function moveScroll(e:MouseEvent):void{           
    	if(draging=true){	
    	s.writeUTFBytes(currentFader.name+svalue.text);
    	s.flush();
    	trace(currentFader.name+svalue.text);
    	e.updateAfterEvent();
    	}
    }
    and the error is

    Code:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    	at D3264NEW_fla::MainTimeline/moveScroll()
    the stuff in the moveScroll function is tracing, but its not outputting to the binary sockets anymore like it used to (s is the variable i used for my socket)

  7. #27
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Fix dropScroll with the last version I posted.

    In moveScroll, you have assignment = instead of comparison ==, which will SET draging to true regardless of what it was before, and go into the if. You don't need the comparison at all since draging (it hurts to keep writing it that way) is boolean.

    Code:
    function moveScroll(e:MouseEvent):void{           
      if(draging){
        s.writeUTFBytes(currentFader.name+svalue.text);
        s.flush();
        trace(currentFader.name+svalue.text);
        e.updateAfterEvent();
      }
    }

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