Hide part of moving container - mask

How do I hide that part of a moving container with Pic2 inside so that it doesn't overlap the container with Pic1? There is a splitter (in white) and it should visually split those moving pictures.
Here is an exmaple: http://cjstest.blg.lt/test.html

You can use the mask property to apply a shape as a clipping path on any DisplayObject.
I ported your example to JSFiddle here: http://jsfiddle.net/lannymcnie/t8dzrunj/
It is important to note that an object's mask is automatically moved to draw at the coordinates of the clip. This means that I had to change the sample so that the rightBG is what is moving (instead of its Container), and then mask the container. Since the container is moved on the x, I had to massage the coordinates of the mask a little, but I got it to work: http://jsfiddle.net/lannymcnie/t8dzrunj/1/
Here is the code to create and apply the mask:
var mask = new createjs.Shape();
mask.graphics.f("#f00").dr(40,0,260,480);
rightSubCont.mask = mask;
Hope this helps!

Related

Creating a border container with border sides and separate corner radius

In the Spark BorderContainer component the border sides and corner radius styles were not copied over from the halo component set (see here).
Specifically:
borderSides (left, top, bottom, right)
cornerRadius(TL/TR/BL/BR)
borderThickness(Left/Right/Top/Bottom) * optional
backgroundAttachment (fixed, scroll) * optional
I've been trying to add them manually but I'm having some difficulty.
I've brought over some code from the HaloBorder.as skin and it is sortof working except it is appearing behind the background fill.
It's a lot of code so I pasted it here.
BTW That code was my first approach. But it looks like I could use the insetPath that is already there to draw border. That would be better since it allows me to set all the stroke properties but I don't know how to write path data so I'd have to learn that as well. But at this point I'd be happy to get anything working.
Update:
I found a class that has some methods for generating curved border path data. Look in spark/skins/spark/TabBarButtonSkin.mxml. You can see the code here, in the createPathData() method.

BitmapData with Scale9Grid

I have a Skin for SkinnableContainer.
Skin contains only the original contentGroup and s:BitmapImage as background.
Background image stretchers out according to width and height content.
The used image is .png with transparent regions.
To create hitarea, I used this algorithm:
http://www.webverwirklichung.com/en/blog/programming/flex/creating-hitarea-png-image-transparent-alpha-regions-flex
Everything's working fine until I start to stretch the SkinnableContainer (along with the image in the skin).
I have a scale9Grid for the image.
The problem is, that when stretching the image, the bitmapData of the image is still the same (same width and height). Therefore I need to somehow obtain the bitmapData of the image for the scale9Grid application.
The background of the component is an image, which has some transparent areas. It is only possible to click on the visible part of the image. The image will stretch according to the content in contentGroup.
Need an advice, please.
How about using the BitmapData.draw() method?
After the container is resized and the 9 slice scaling has been applied (or whatever the appropriate trigger is) do:
var b:BitmapData = new BitmapData(container.width, container.height);
b.draw(container);
Then use this new bitmap with the algorithm that creates the hit area.

Filtering out all but a specific color of an image in Flex

Let's say I have an Image in Flex, and I want to filter it such that only the Green Pixels are visible...
For example this image:
alt text http://www.LiquidFeline.com/Images/Circles.png
Would show up on the screen as:
alt text http://www.LiquidFeline.com/Images/Circles2.png
How can I accomplish this in Actionscript/Flex?
You can do this easily with the threshold method of the BitmapaData class.
Basically, make a copy of the image. Then make every pixel that fails to pass the threshold test fully transparent. The test in this case could be pixel != your shade of green.
Sample code:
var color:uint = 0xff22b14c;
var bmd:BitmapData = new BitmapData(image.width,image.height,true);
bmd.draw(image);
bmd.threshold(bmd,new Rectangle(0,0,image.width,image.height),new Point(0,0),"!=",color,0,0xffffffff);
addChild(new Bitmap(bmd));
With a bit more of work you could isolate ranges of colors, but for a solid color as in your case, this should do it.
You can try applying chromakey effects the Bitmap and BitmapData classes. See a tutorial at http://cnx.org/content/m34463/latest/

Raphael JS resize Canvas

I'm programming a debate-graph with Raphael JS. Users can add nodes to the graph. Eventually the graph gets really big and the canvas is still the same size. the canvas (in raphael js: paper) is inside another div with "overflow: scroll;", so lets ignore screen real estate
Is there a way that I resize the canvas without reloading the page (to assign new X/Y values)?
Alternatively, can I create a second bigger canvas in parallel and copying all the elements over? is there a way?
If I understand your question, just call setSize() to expand the size of the canvas to the size needed as you need it. I've used this in a div with overflow:scroll to get the effect you describe.
In my case, I didn't want to resize, I wanted to zoom.
In other words, show the user the growing graph inside a constant-sized div.
So I needed: setViewBox()

how can move the child only inside the parent?

Recently I worked in a project using Flex. Its a Photo editing project. I have took a Canvas and take a image in that canvas using the code canvas.addChild(image) . Now i can move the image freely by using moving code. The image move inside the canvas and outside the canvas. I want to move the image/child only inside the canvas not outside. How can i do this?
There are two ways to do this:
Bounding Rectangle
Scroll Rectangle (or Mask)
Assuming your "moving code" is something like an Event.ENTER_FRAME handler initialized onClick, you want to make it so the image can't leave the bounds of the parent Canvas.
The first case (bounding rectangle) will allow you to drag the image within the retangle but you will always be able to see the whole image. This is how Image croppers work.
To create a bounding rectangle, you'll have to write a fairly detailed method, but the idea behind it is simple. Just get the bounding rectangle from the canvas, and don't let the image.x go below 0 and don't let image.x + image.width go beyond canvas.width. Same with height. Here's a sample Image Cropper in Flex (and the source). Check out how they did it for details.
The second case (scroll rectangle) would allow you to create more of a pan/zoom like container like you see on this Flex Pan/Zoom Map (here's the source). Also, the large image in the Flex Image Cropper on the right is an example of this second case, but they don't have the dragging. That requires that you manipulate the position of the scrollRect property on the canvas. The scrollRect property is a flash.geom.Rectangle defining the Canvas' "viewport". You then change/update the verticalScrollPosition and horizontalScrollPosition properties, so it's backwards (compared to the Bounding Rectangle).
I think if you set clipAndEnableScrolling to true on the canvas, and you drag a child image around inside of it (and image.includeInLayout = true), it should clip the image to only show up inside the canvas. But I'm guessing you want case 1. Just search those properties and you'll find some good examples on google.
Good luck, should be a fun project.
Lance

Resources