AS3 sprite stroke

  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

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.  
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

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.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

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
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

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...
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

ATNO...thanks as always!!! You're the best!
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

I take that to mean you got it to work?
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

No sir...sorry I was just thanking you for your input...still not working
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

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
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

http://qa.palmetto-bluff.com/swf/compilation.fla
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

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?
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

everything is working like a dream except that the linestyle is removed when I loop through the squares and colorTransform them to beige
  • s15199d
  • Expert
  • Expert
  • User avatar
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

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.
  • zhaojany
  • Student
  • Student
  • User avatar
  • Posts: 79

Post 3+ Months Ago

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
  • Posts: 524
  • Loc: NC, USA

Post 3+ Months Ago

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
  • zhaojany
  • Student
  • Student
  • User avatar
  • Posts: 79

Post 3+ Months Ago

you welcome :)
  • youjustknow
  • Born
  • Born
  • youjustknow
  • Posts: 1

Post 3+ Months Ago

I was wanting to do something similar, I had a rectangle created in a class with an event listener checking for a click, when I click the rectangle I wanted it to have a stroke colour added to it.

in the event listener click function i simply added this code.

Code: [ Select ]
var checkArray:Array=new Array ;

        public function containerClass() {

            // Creates the container for the card symbols to be added into

            var cardHolder:Sprite = new Sprite();
            cardHolder.graphics.beginFill(0xFFFFFF);
            cardHolder.graphics.drawRoundRect(0,0,225.061,150.929,15,15);


            this.addChild(cardHolder);
            cardHolder.(don't write whats in the brackets)name="cardHolder";

            //var counts the card clicks

            addEventListener(MouseEvent.CLICK,checker);



            function checker(evt:MouseEvent):void {
                trace(docClass.clicksCounter);
                docClass.clicksCounter++;
                
                /*cardHolder.graphics.clear();*/
                var newCardHolder:Sprite = new Sprite();
                newCardHolder.graphics.lineStyle(3,0xFF0099);
            
            newCardHolder.graphics.drawRoundRect(0,0,225.061,150.929,15,15);


            addChild(newCardHolder);
            newCardHolder.(don't write whats in the brackets)name="newCardHolder";
}
  1. var checkArray:Array=new Array ;
  2.         public function containerClass() {
  3.             // Creates the container for the card symbols to be added into
  4.             var cardHolder:Sprite = new Sprite();
  5.             cardHolder.graphics.beginFill(0xFFFFFF);
  6.             cardHolder.graphics.drawRoundRect(0,0,225.061,150.929,15,15);
  7.             this.addChild(cardHolder);
  8.             cardHolder.(don't write whats in the brackets)name="cardHolder";
  9.             //var counts the card clicks
  10.             addEventListener(MouseEvent.CLICK,checker);
  11.             function checker(evt:MouseEvent):void {
  12.                 trace(docClass.clicksCounter);
  13.                 docClass.clicksCounter++;
  14.                 
  15.                 /*cardHolder.graphics.clear();*/
  16.                 var newCardHolder:Sprite = new Sprite();
  17.                 newCardHolder.graphics.lineStyle(3,0xFF0099);
  18.             
  19.             newCardHolder.graphics.drawRoundRect(0,0,225.061,150.929,15,15);
  20.             addChild(newCardHolder);
  21.             newCardHolder.(don't write whats in the brackets)name="newCardHolder";
  22. }

Post Information

  • Total Posts in this topic: 16 posts
  • Users browsing this forum: No registered users and 4 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.