AS3 sprite stroke

  • s15199d
  • Expert
  • Expert
  • User avatar
  • Joined: Feb 20, 2004
  • Posts: 524
  • Loc: NC, USA
  • Status: Offline

Post October 8th, 2008, 4:29 am

I don't understand why this work
Code: [ Select ]
getChildAt(i).alpha = 0;
and this doesn't work
Code: [ Select ]
getChildAt(i).graphics.lineStyle


Code: [ Select ]
 
//THIS WORKS
var newColour:ColorTransform=Nav.getChildAt(i).transform.colorTransform;
newColour.color=0xCCB589;
Nav.getChildAt(i).transform.colorTransform=newColour;
 
//THIS PRODUCES AN ERROR
Nav.getChildAt(i).graphics.lineStyle(1, 0xFFFFFF);
 
//THIS WORKS
Nav.getChildAt(i).alpha = 0;
 
//NO ERROR BUT DOESN'T WORK
var curSquare:Sprite = Sprite(Nav.getChildAt(i));
curSquare.graphics.lineStyle(1, 0xFFFFFF);
 
  1.  
  2. //THIS WORKS
  3. var newColour:ColorTransform=Nav.getChildAt(i).transform.colorTransform;
  4. newColour.color=0xCCB589;
  5. Nav.getChildAt(i).transform.colorTransform=newColour;
  6.  
  7. //THIS PRODUCES AN ERROR
  8. Nav.getChildAt(i).graphics.lineStyle(1, 0xFFFFFF);
  9.  
  10. //THIS WORKS
  11. Nav.getChildAt(i).alpha = 0;
  12.  
  13. //NO ERROR BUT DOESN'T WORK
  14. var curSquare:Sprite = Sprite(Nav.getChildAt(i));
  15. curSquare.graphics.lineStyle(1, 0xFFFFFF);
  16.  
Image
Give a man a fish he eats for a day. Teach a man to fish he eats for a lifetime.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post October 8th, 2008, 4:29 am

  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Joined: May 28, 2003
  • Posts: 23407
  • Loc: Woodbridge VA
  • Status: Offline

Post October 8th, 2008, 4:52 am

I haven't gotten far enough in my AS3 studies to work with sprites yet, so I'm not 100% certain how they work, but I did do this similar thing in an exercise yesterday drawing shapes. My thought is even though you're working with a sprite it probably should still be similar to this which draws a white circle:

Code: [ Select ]
var shape:Shape = new Shape();

shape.graphics.linestyle(1,0xFFFFFF);
shape.graphics.drawCircle(100,100,50);
addChild(shape);
  1. var shape:Shape = new Shape();
  2. shape.graphics.linestyle(1,0xFFFFFF);
  3. shape.graphics.drawCircle(100,100,50);
  4. addChild(shape);


If the logic is the same I'm thinking:
Code: [ Select ]
var curSquare:Sprite = new Sprite(Nav.getChildAt(i));

curSquare.graphics.lineStyle(1, 0xFFFFFF);
addChild(curSquare);
  1. var curSquare:Sprite = new Sprite(Nav.getChildAt(i));
  2. curSquare.graphics.lineStyle(1, 0xFFFFFF);
  3. addChild(curSquare);


Like I said, that's just guessing based on how you draw a shape. I don't know enough about sprites yet to know exactly how they work.
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Joined: May 28, 2003
  • Posts: 23407
  • Loc: Woodbridge VA
  • Status: Offline

Post October 8th, 2008, 5:14 am

I just found this tutorial. Don't know if it will help, but might want to take a look.

http://www.actionscript.org/resources/a ... Page1.html
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Joined: Feb 20, 2004
  • Posts: 524
  • Loc: NC, USA
  • Status: Offline

Post October 8th, 2008, 5:27 am

I should have clarified my issue a bit more...

This code works like a dream:
Code: [ Select ]
 
var square3:Sprite = new Sprite();
square3.graphics.lineStyle(1, 0xFFFFFF);
square3.graphics.beginFill(0xCCB589);
square3.graphics.drawRect(60, 385, 10, 10);
square3.graphics.endFill();
square3.buttonMode = true;
square3.addEventListener(MouseEvent.CLICK, clicked3);
 
  1.  
  2. var square3:Sprite = new Sprite();
  3. square3.graphics.lineStyle(1, 0xFFFFFF);
  4. square3.graphics.beginFill(0xCCB589);
  5. square3.graphics.drawRect(60, 385, 10, 10);
  6. square3.graphics.endFill();
  7. square3.buttonMode = true;
  8. square3.addEventListener(MouseEvent.CLICK, clicked3);
  9.  


Then I programatically change the color with this:
Code: [ Select ]
 
var newColour:ColorTransform=Nav.getChildAt(i).transform.colorTransform;
newColour.color=0xCCB589;
Nav.getChildAt(i).transform.colorTransform=newColour;
 
  1.  
  2. var newColour:ColorTransform=Nav.getChildAt(i).transform.colorTransform;
  3. newColour.color=0xCCB589;
  4. Nav.getChildAt(i).transform.colorTransform=newColour;
  5.  


When I do the "ColorTransform" my "lineStyle" from above get's over-wrote.

So, I'm trying to re-add the line-style, but the getChildAt(i) has been a road block...

I've tried:
Code: [ Select ]
 
1)
Nav.getChildAt(i).graphics.lineStyle(1, 0xFFFFFF);
 
  1.  
  2. 1)
  3. Nav.getChildAt(i).graphics.lineStyle(1, 0xFFFFFF);
  4.  


and this:

Code: [ Select ]
 
2)
var curSquare:Sprite = Sprite(Nav.getChildAt(i));
curSquare.graphics.lineStyle(1, 0xFFFFFF); 
 
  1.  
  2. 2)
  3. var curSquare:Sprite = Sprite(Nav.getChildAt(i));
  4. curSquare.graphics.lineStyle(1, 0xFFFFFF); 
  5.  


and this:

Code: [ Select ]
 
3)
var curSquare:Sprite = new Sprite();
curSquare = Sprite(Nav.getChildAt(i));
curSquare.graphics.lineStyle(1, 0xFFFFFF); 
Nav.addChild(curSquare);
 
  1.  
  2. 3)
  3. var curSquare:Sprite = new Sprite();
  4. curSquare = Sprite(Nav.getChildAt(i));
  5. curSquare.graphics.lineStyle(1, 0xFFFFFF); 
  6. Nav.addChild(curSquare);
  7.  


None of the 3 have worked...
Image
Give a man a fish he eats for a day. Teach a man to fish he eats for a lifetime.
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Joined: Feb 20, 2004
  • Posts: 524
  • Loc: NC, USA
  • Status: Offline

Post October 8th, 2008, 5:28 am

ATNO...thanks as always!!! You're the best!
Image
Give a man a fish he eats for a day. Teach a man to fish he eats for a lifetime.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Joined: May 28, 2003
  • Posts: 23407
  • Loc: Woodbridge VA
  • Status: Offline

Post October 8th, 2008, 5:32 am

I take that to mean you got it to work?
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Joined: Feb 20, 2004
  • Posts: 524
  • Loc: NC, USA
  • Status: Offline

Post October 8th, 2008, 5:35 am

No sir...sorry I was just thanking you for your input...still not working
Image
Give a man a fish he eats for a day. Teach a man to fish he eats for a lifetime.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Joined: May 28, 2003
  • Posts: 23407
  • Loc: Woodbridge VA
  • Status: Offline

Post October 8th, 2008, 5:47 am

have an FLA? duplicating your original sprite is easy enough but I get all kinds of parameter errors when I try anything else because I've no clue what else you're doing
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Joined: Feb 20, 2004
  • Posts: 524
  • Loc: NC, USA
  • Status: Offline

Post October 8th, 2008, 5:50 am

http://qa.palmetto-bluff.com/swf/compilation.fla
Image
Give a man a fish he eats for a day. Teach a man to fish he eats for a lifetime.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Joined: May 28, 2003
  • Posts: 23407
  • Loc: Woodbridge VA
  • Status: Offline

Post October 8th, 2008, 7:03 am

I'm sorry, I've reviewed your FLA and it's working without errors for me (except for the missing image URL's which has nothing to do with your script).

It appears to be doing exactly what you told it to, i.e. sequentially changing the colors of the squares to white and then back to beige as the next one in the sequence changes to white. What exactly is it that you want it to do?
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Joined: Feb 20, 2004
  • Posts: 524
  • Loc: NC, USA
  • Status: Offline

Post October 8th, 2008, 2:27 pm

everything is working like a dream except that the linestyle is removed when I loop through the squares and colorTransform them to beige
Image
Give a man a fish he eats for a day. Teach a man to fish he eats for a lifetime.
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Joined: Feb 20, 2004
  • Posts: 524
  • Loc: NC, USA
  • Status: Offline

Post October 8th, 2008, 2:42 pm

I didn't resolve the issue...

I have however worked around the issue...by using transparent sprites (aka sprites with no fill)

And, I know a bit more about the conundrum...

Long and short of it...

The ColorTransform not only "transforms" the fill, but also transforms the linestyle.
Image
Give a man a fish he eats for a day. Teach a man to fish he eats for a lifetime.
  • zhaojany
  • Student
  • Student
  • User avatar
  • Joined: Aug 03, 2006
  • Posts: 78
  • Status: Offline

Post October 9th, 2008, 8:02 pm

first the ColorTransform had overwritten your stroke, so if there was a stroke and you applied the ColorTransform to it but you wont see the stroke;

second i dont think we can change the linestyle itself, the only way is to redraw it . but before that you should use the graphics.clear() method to clear the prev draw. and cant just only reset the linestyle.

hope it help :wink:
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Joined: Feb 20, 2004
  • Posts: 524
  • Loc: NC, USA
  • Status: Offline

Post October 13th, 2008, 4:51 am

sounds about right zhaojany

Thank you, for clarifying

I ended up working around this lil quirk...

I made an "off" and an "on" version of the box (that's what the linestyle and colortransform were meant to represent)...anyways I just programatically toggle alpha between the two...

Not as eficient as I had hoped, but it gets the job done...

http://qa.palmetto-bluff.com/swf/compilation.fla
Image
Give a man a fish he eats for a day. Teach a man to fish he eats for a lifetime.
  • zhaojany
  • Student
  • Student
  • User avatar
  • Joined: Aug 03, 2006
  • Posts: 78
  • Status: Offline

Post October 15th, 2008, 2:15 am

you welcome :)
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post October 15th, 2008, 2:15 am

Post Information

  • Total Posts in this topic: 16 posts
  • Users browsing this forum: No registered users and 32 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.