Go Back   CodingForums.com > :: Client side development > Flash & ActionScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-25-2008, 11:19 PM   PM User | #1
Kirl
Regular Coder

 
Join Date: Jan 2006
Posts: 243
Thanks: 14
Thanked 2 Times in 2 Posts
Kirl is on a distinguished road
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);
}
Kirl is offline   Reply With Quote
Old 10-26-2008, 01:25 AM   PM User | #2
itsallkizza
Senior Coder

 
Join Date: Oct 2008
Location: Long Beach
Posts: 1,196
Thanks: 36
Thanked 164 Times in 164 Posts
itsallkizza will become famous soon enough
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..
itsallkizza is offline   Reply With Quote
Old 10-26-2008, 01:06 PM   PM User | #3
Kirl
Regular Coder

 
Join Date: Jan 2006
Posts: 243
Thanks: 14
Thanked 2 Times in 2 Posts
Kirl is on a distinguished road
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..
Kirl is offline   Reply With Quote
Old 10-26-2008, 08:14 PM   PM User | #4
Kirl
Regular Coder

 
Join Date: Jan 2006
Posts: 243
Thanks: 14
Thanked 2 Times in 2 Posts
Kirl is on a distinguished road
Got it to work by changing the "this" in the createMovieClip to "line" directly. Thanks for the help!
Kirl is offline   Reply With Quote
Old 10-27-2008, 03:45 AM   PM User | #5
itsallkizza
Senior Coder

 
Join Date: Oct 2008
Location: Long Beach
Posts: 1,196
Thanks: 36
Thanked 164 Times in 164 Posts
itsallkizza will become famous soon enough
ah sweet, good to know
itsallkizza is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:05 PM.


Advertisement
Log in to turn off these ads.