Home » Adobe, Flash Catalyst

Optimizing MXML code in Flash Catalyst “Panini” - Part 7:
TextInput Component

14 February 2011 No Comment

In this chapter we will create the TextInput field of the ActionBar so the user can type text.

You need to read previous chapters in order to understand this article.

First remove the static label “Search in the blog” of the BlogView component imported from Illustrator.
Open the BlogView component, select the object using the Select tool and press DELETE from the keyboard.

001_removethestubtextfield

-
NOTE: TEXT OBJECTS IN FLASH CATALYST
If in the Illustrator Import settings you set the Text property to “Keep Editable“(see Chapter 001) the text fields are automatically converted to Spark RichText components whose contents can be edited directly in Catalyst and later in Flex.

<s:RichText fontFamily="Arial" fontSize="18" text="Search in the blog..." />

However, this component does not allow the inclusion of content by the user and will be removed.
Instead we will create a special TextInput component using the white rectangle in the layout.

<s:TextInput text="Type a word..."/>

-

After removing the static label, select the white rectangle from BlogView component and convert it in TextInput giving the component name BlogInputText.
002_textinputselection

When you select any part of the artboard, in this case the TextInput just created, you can define the properties from the Propertiespanel.
Change the Text property (currently empty) to set the default text displayed by the input field.
003_typeaword

The change will be immediately visible in the workspace
004_typeawordpreview

However, the default text font is too small and we will then enlarge it.
To change the size and position of the text field you need to edit the BlogInputText component (right click on the component > Edit component)
005_edittextinput

Select the text field within the component BlogInputText using the Select tool.
006_selecttextfield

Change the font size from the Properties panel using the Size property and change the other options you need.
007_modifypropertytextfield

Manually center the text field using the Select tool
008_repositiontextfield

Compiling the project (CTRL + ENTER) users can now write inside the TextInput of the BlogList state.
009_output





THE GENERATED MXML CODE

The component BlogView.mxml now contains an instance of the Spark TextInput component, which will use the new BlogInputText skin.

[]
<s:TextInput x="100" y="12" enabled="true" 
			 skinClass="components.BlogInputText"
			 text="Type a word..."/>
[]

Here is the skin mxml code - BlogInputText.mxml - used by the TextInput component.
Note that inside a new RichEditableText instance has been createad, instead of the RichText component previously used.

<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:s="library://ns.adobe.com/flex/spark"
		xmlns:fx="http://ns.adobe.com/mxml/2009"
		xmlns:fc="http://ns.adobe.com/flashcatalyst/2009"
		xmlns:d="http://ns.adobe.com/fxg/2008/dt"
		fc:resizable="false">
	<fx:Metadata>[HostComponent("spark.components.TextInput")]</fx:Metadata>
	<s:states>
		<s:State name="normal"/>
		<s:State name="disabled"/>
		<s:State name="normalWithPrompt"/>
		<s:State name="disabledWithPrompt"/>
	</s:states>
	<s:Rect d:userLabel="TextBg" x="0.5" y="0.5" width="312" height="45">
		<s:fill>
			<s:SolidColor color="#F2F2F2"/>
		</s:fill>
		<s:stroke>
			<s:SolidColorStroke caps="none" joints="miter" miterLimit="10" color="#333333"/>
		</s:stroke>
	</s:Rect>
 
 
	<s:RichEditableText id="textDisplay" x="5" y="5" width="303" heightInLines="1"
						x.normal="6" y.normal="13" fontSize.normal="22"
						tabStops.normal="S0 S50 S100 S150 S200 S250 S300" fontFamily="Arial"/>
</s:Skin>

The project named 007_TextInput.fxp (available in the next days) attached to the tutorial contains all the code generated so far.





-
RELATED ENTRIES

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.