Showing posts with label fxg. Show all posts
Showing posts with label fxg. Show all posts

Friday, May 8, 2009

FXG Tutorial : Understanding Paths

Continuing on the FXG Tutorials, in this tutorial, we will be seen Paths in FXG. Paths represent the outline of a shape in FXG. Paths are created using the Path element and the co-ordinates are given in its data attribute. A Path element supports fills,strokes,filters and blendmodes.



Path data contains numbers and specific letters which specify instructions (M indicates a moveto command, the L indicate lineto command, and the z indicates a closepath command).


Here is the example:



<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns="library://ns.adobe.com/flex/spark">

<fx:Library>

<fx:Definition name="Triangle">
<Group>
<Path data="M 100 100 L 50 200 L 150 200 z">
<fill>
<SolidColor color="#FF0000" />
</fill>
<stroke>
<SolidColorStroke weight="3" color="#0000FF" />
</stroke>
</Path>
</Group>
</fx:Definition>

<fx:Definition name="Square">
<Group>
<Path data="M 100 100 L 200 100 L 200 200 L 100 200 z">
<fill>
<SolidColor color="#FF0000" />
</fill>
<stroke>
<SolidColorStroke weight="3" color="#0000FF" />
</stroke>
</Path>
</Group>
</fx:Definition>

</fx:Library>

<Group>
<layout> <HorizontalLayout/> </layout>
<fx:Triangle/>
<fx:Square/>
</Group>

</Application>

As you can see, in the Path data of the Triangle,we have . This merely says : First, Move to 100,100. Then draw a Line to 50,200. Then draw a Line to 150,200. Then close the Path. We can use this to draw any shape that we want easily. You can read more here. Happy experimenting :D. Feel free to drop a comment about anything. Happy experimenting :D

FXG Tutorial : Creating and using Symbols

In the previous tutorial, I showed you how to create a simple Hello World tutorial in FXG. In this tutorial, we will be creating and using symbols. Symbols are nothing but a set of graphics with a defined name which can used to use it multiple times without having to rewrite the code.Here is the code:



<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns="library://ns.adobe.com/flex/spark">

<fx:Library>
<fx:Definition name="Square">
<Group>
<Rect width="200" height="200">
<fill>
<SolidColor color="#FF0000" />
</fill>
</Rect>
</Group>
</fx:Definition>

<fx:Definition name="Circle">
<Group>
<Ellipse width="200" height="200">
<fill>
<SolidColor color="#FF0000" />
</fill>
</Ellipse>
</Group>
</fx:Definition>

<fx:Definition name="SampleText">
<Group>
<SimpleText text="This is a sample text"/>
</Group>
</fx:Definition>
</fx:Library>

<Group>
<layout>
<VerticalLayout/>
</layout>

<fx:Square/>
<fx:Circle/>
<fx:SampleText/>
</Group>

</Application>


We can create symbols with the Definition tag. The definitions must be placed inside of the Library tag. As you can see, in the Definition tag, the name attribute is used to specify the name for the symbol. FXG also allows 2D transformations with the Matrix class. We can also apply Flex effects,filters,transitions,etc. in FXG.Happy Experimenting :D

FXG Tutorial : Getting Started with a Hello World Example.

FXG is an XML based graphics interchanged format for the Flash Platform. In this tutorial,we are going to get started with FXG with a simple Hello World example. So after you set up Flex Builder with the latest nightly build of Flex 4, (You can see how here if you don’t know.) we can start.

FXG documents have a logical structure. The Graphic element serves as the root for any FXG document. The Group elementis used to group related graphic elements.Currently, basic shapes such as Rectangle and Ellipse can provided but we can easily create our required shapes with the given functions.We can add text with the SimpleText tag which provides simple text formatting as well.

Here is the Hello World code:



<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns="library://ns.adobe.com/flex/spark">

<Graphic>
<Group>
<Rect width="200" height="200">
<fill>
<SolidColor color="#000000"/>
</fill>
<stroke>
<SolidColorStroke weight="3" color="#FF0000"/>
</stroke>
</Rect>
<SimpleText text="Hello World" x="50" y="50"/>
</Group>
</Graphic>

</Application>


This will create a black square with a red stroke with the text “Hello World”. I’ll be posting more tutorials on FXG soon. Happy experimenting :D