Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Posts
    243
    Thanks
    14
    Thanked 2 Times in 2 Posts

    drawing to multiple empty MC's

    I have a function that I want to use to draw multiple lines onto/into the "line" MC, but I keep overwriting previous lines. Usually when attaching multiple MC's from the library I do something like this:
    Code:
    attachMovie("Ball", "ball"+balls.length, getNextHighestDepth(), etc..
    So I thought I could do something similar with createEmptyMC:
    Code:
    line.createEmptyMovieClip("puddle"+puddles.length, getNextHighestDepth());
    But when I do this like the latter example nothing shows up on stage. Without adding the "+puddles.length" it shows up, but I seem to overwrite the last line when adding a new. Below is the function I'm using, which seems to work ok except for the fact that only the last call will show. The drip is just a visual touch I add to each line.

    Any idea what I'm doing wrong?


    Code:
    function draws(from, to, color)
    {
    	line.createEmptyMovieClip("puddle", this.getNextHighestDepth());	
    	line.puddle.lineStyle(20, color, 100);
    	line.puddle.moveTo(from, bottom);
    	line.puddle.lineTo(to, bottom);
    	line.puddle.color = color;             
    	line.puddle.attachMovie("drip", "drip", getNextHighestDepth(), {_x:to, _y:bottom});
    	new Color(line.puddle.drip).setRGB(color);
    	puddles.unshift(line.puddle);
    }

  • #2
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    This might be exactly what you were talking about, but it's what I'd do:
    Code:
    var puddles:Array = new Array();
    function draws(from,to,color):Void
    {
    	var t:MovieClip = line.createEmptyMovieClip("puddle"+puddles.length,this.getNextHighestDepth());
    	puddles.unshift(t);	
    	t.lineStyle(20,color,100);
    	t.moveTo(from,bottom);
    	t.lineTo(to,bottom);
    	t.color = color;             
    	t.attachMovie("drip","drip",t.getNextHighestDepth(),{_x:to,_y:bottom});
    	new Color(t.drip).setRGB(color);
    }
    Make sure bottom is defined somewhere (since it's not being passed in).

    You can also overwrite mcs by giving them the same depth, which you might have been doing with "getNextHighestDepth()" (because you weren't attaching the new mc to the same layer you were getting the next depth from, the next depth wasn't changing - maybe anyway, without seeing the rest of your code ). Make sure all no names are the same within the same mc layer (which you already knew) and also make sure they are all assigned to separate depths.
    Last edited by itsallkizza; 10-26-2008 at 01:29 AM.

  • #3
    Regular Coder
    Join Date
    Jan 2006
    Posts
    243
    Thanks
    14
    Thanked 2 Times in 2 Posts
    Thanks, that code looked better already, it still seems to overwrite the last line though, only the last call shows. I call the function twice at the end of my initialisation function in which I set everything up, like this:

    Code:
    function initialise()
    {	
    	... // some code
    	
    	createEmptyMovieClip("line", getNextHighestDepth());
    
    	draws(Stage.width/2, Stage.width/2+50, 0xff0000);
    	draws(100, 150, 0x00ff00);
    }
    Only the 2nd green one shows up. Bottom is a global variable so that should be fine.


    [edit] Not sure if it's important but I clear the "line" MC at every frame (line.clear()) before redrawing what needs to be. However at first I thought these "puddles" would be cleared as well because they're basically inside the "line" MC (line.puddles). But they aren't cleared which is good, because the lines this function draws don't need to be redrawn at every frame. I guess it's normal behaviour but it was new to me.
    Last edited by Kirl; 10-26-2008 at 01:37 PM.

  • #4
    Regular Coder
    Join Date
    Jan 2006
    Posts
    243
    Thanks
    14
    Thanked 2 Times in 2 Posts
    Got it to work by changing the "this" in the createMovieClip to "line" directly. Thanks for the help!

  • #5
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    ah sweet, good to know


  •  

    Posting Permissions

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