I'm using TweenMax to make all tweens, fade in a projet. Now my question is : is it possible to tween only linestyle from a Sprite ?
For example, something like that :
TweenMax.to ( my_sprite.graphics.lineStyle, 0.5, { tint : 0xFF0000 } );
Thank you.
From what I have seen, if you wish to alpha the stroke and the fill separately, you need to redraw the shape.
ie. this post - http://www.actionscript.org/forums/showthread.php3?t=219378
Alternatively, depending on the complexity of the Sprite, you can just make the outline its own Sprite and tween it interdependently.
Related
Is there a way to have a movie clip in your flash game and when something happens (such as a mouse hovering over it) for it to become lighter or darker?
MovieClip.addEventListener(MouseEvent.MOUSE_OVER, onContact);
public function onContact(event:MouseEvent):void
{
//Not Sure What To Put Here
}
Is there a way to do this?
Thanks in advance,
Jason
Every object that has a colorTransform has the ability to manipulate it's colour.
For example try this:
public function onContact(contact:MouseEvent):void
{
var displayObject:DisplayObject = contact.currentTarget as DisplayObject;
displayObject.transform.colorTransform = new ColorTransform( .3, .3, .3); // makes object darker
}
Also, it's common to use tweening engines like TweenLite/TweenMax (http://www.greensock.com/tweenmax/) to tween the colorTransform. If you'll navigate to the provided link there is a plug-in explorer that allows you to test and experiment with different tweening plug-ins including Color Transform.
I have a png which has mainly two colors as background. I'd want to know if as3 provides methods to select a color to make it transparent.
Take a look at BitmapData class.
You can get color of each pixel and set transparency for some of them.
One option is to use the BitmapData method threshold :
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#threshold%28%29
public function threshold(sourceBitmapData:BitmapData, sourceRect:Rectangle, destPoint:Point, operation:String, threshold:uint, color:uint = 0, mask:uint = 0xFFFFFFFF, copySource:Boolean = false):uint
I need to place a transparent sprite over another sprite. The overlaying sprite will acept some mouse events. When a user move mouse over upper sprite a curve will be drawn. After it'll be processed it will be drawn on the base sprite (and erased on upper).
The idea I have now is to place the sprite, draw a rectange of size equal to sizes of sprite and set alpha to 0.
The question is a bit dump: maybe the proposed solution is not the best. Is there a better way to set width and height (as far a I understand Sprite.width = w; will not help)?
Thank you in advance!
You can't set dimensions directly, while you can draw over that Sprite. So you can do like this:
graphics.beginFill(0,0); // zero alpha fill
graphics.lineStyle(0,0,0); // invisible lines
graphics.drawRect(0,0,width,height);
graphics.endFill();
This way your Sprite can have its alpha remaining at 1, to not hide anything that's its child. Then, whatever curve you would decide to draw in that Sprite, you can draw within a child Shape object, via graphics.moveTo and graphics.lineTo.
UPDATE: According to comments below, setting alpha to 0 won't work with newer Flash player versions, so alpha should be set to a nonzero amount for the events to register on the overlapping sprite.
graphics.beginFill(0x808080,0.01); // almost zero alpha fill
I'm trying to mask a movieclip using a mask created with AS3 but it changes the color of the movieclip being masked. I would like the mask to not change the color of the masked movieclip. Here is my code:
mask_mc.mask=masked_mc;
drawMask();
function drawMask():void {
mask_mc.graphics.clear();
mask_mc.graphics.beginFill(0x000000,1);
mask_mc.graphics.drawRect(0,0,750,250);
mask_mc.graphics.endFill();
}
The masked movieclip becomes the same color as the color defined in beginFill. In the example above, masked_mc turns black (as defined in beginFill). Removing beginFill masked everything and revealed nothing. I've not found anyone else having this problem. Perhaps I going about this all wrong. Thanks in advance for any help on masking with AS3 without changing the color of the movieclips being masked.
You also have to add the mask into the display list :
SomeClip.addChild(masked_mc)
and i see that you are drawing on your clip and not on your mask so it may explain the color you see :
var g:Graphics = masked_mc.graphics
g.clear()
g.beginFill(0x000000,1)
g.drawRect(0,0,750,250)
g.endFill()
I would like to tween between a short rounded rectangle and a tall rounded rectangle. (I only want deal with the height - no other parameters). I am programming with actionscript 3. My tweening engine is TweenLite.
I have been tweening a sprite that contains a rounded rectangle. The tweened sprite produces distortion. I suppose that I have been scaling the original image, rather than the height of the rounded rectangle?
Here is a simple example of my code:
-
Draw the rounded rectangle:
roundRect = new Sprite();
roundRect.graphics.beginFill(0x000000);
roundRect.graphics.drawRoundRect(0,0,50,15,4,4); //Original Height: 15
roundRect.graphics.endFill();
addChild(roundRect);
Then I listen for a mouse click event on the rounded rectangle.
The mouse event triggers a function with the following code:
TweenLite.to(this.roundRect, 1, {height:120}); //Final Height: 120
-
I would like to tween the height of the rounded rectangle itself. I would hope that this would not produce the unwanted distortion. Is there any way to achieve this?
Thank you.
This can be achieved with "9-slice scaling".
Below are two tutorials on how to setup a Movieclip to use the 9-slice guides, one is done through the IDE (using the guidelines) and the other through code (by defining a rectangle called grid and assigning this to the movieclip's scale9Grid property).
http://www.sephiroth.it/tutorials/flashPHP/scale9/
http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001003.html
Once the scale9Grid property has been correctly assigned you can scale (and Tween) the movieclip as intended without any distortion.
It might also be worth reading: http://www.ovidiudiac.ro/blog/2009/05/scale9grid-work-and-fail/ which describes various scenarios when scale9grid does and doesn't work. (mainly to do with having nested children and non-vector graphics inside of the grid).
Hope this helps.
As an alternative, and since its only a rounded rectangle, you could also do something like this:
var rectHeight = 15;
var roundRect = new Sprite();
addChild(roundRect);
updateRect();
function updateRect() {
roundRect.graphics.clear();
roundRect.graphics.beginFill(0x000000);
roundRect.graphics.drawRoundRect(0,0,50,rectHeight,4,4);
roundRect.graphics.endFill();
}
roundRect.addEventListener("click", click);
function click(e) {
TweenLite.to(this, 1, {rectHeight:120, onUpdate:updateRect});
}