Subscribe to RSS
get email updates
home | about | pixDif AIR app | video tutorials
polyGeek.com

Register for 360Flex in DC using the ad below and you will automatically be entered in a drawing for a free ticket. Read more.
place your ad here

Web Premium





Setting a TextArea’s height to its contentHeight

February 28th, 2010 . by polygeek

You would think it would be easy to set a TextArea’s height to its contentHeight. Well, it is easy once you dig, and dig and dig for properties. Why there isn’t a property setHeightToContentHeight is beyond me. But there’s also not a property fixBugsOnApplicationInit which I think would be pretty darn handy.

This seems to be working for me:

<s:TextArea
     id="ta"
     updateComplete="{ ta.height = ta.scroller.viewport.contentHeight + 2 }"; />

“Why is there the +2 at the end?”, you ask.

“I didn’t build the frakking thing!”, I reply.

Really, I have no clue why I have to tack on 2 to the height but if I don’t then sometimes I get the dreaded vertical scrollBar. So, I add 2. Call me crazy.

Instructions
Just add text to the text input TextArea and it will be copied to the text output field. The height of the text output TextArea will grow as the number of lines of text increase.

view source

You might want to set the verticalScrollPolicy=”off” of the TextArea. Otherwise the scrollBar will blink in and out when content is added. I left it on for the example so that you could see the effect.

If something here has proved valuable to you then feel free to drop a couple of bucks in the tip-jar.

Post to Twitter Post to Delicious Post to Facebook Post to Reddit Post to StumbleUpon


similar posts

Keyframes are back! Using Keyframe animations in Flex 4

February 27th, 2010 . by polygeek

The one thing that traditional Flash applications have that Flex doesn’t is keyframes. Well no more. Flex 4 introduces Keyframe class that we can use to create animations from one keyframe to another to another. . .

Actually this isn’t anything hugely new. We could always animate from one property to another in a sequence which is pretty much all this dose. Keyframes just make it slightly easier and more intuitive.

Below is a simple explorer that lets you dynamically add keyframes to a motion path. When I say simple I really mean it. It just tweens the x/y values of the button. But it could just as well tween the z, or alpha, or any number of other properties.

view source

Chet Haase has an excellent short video intro that you should watch on keyframe animation in Flex 4.

If something here has proved valuable to you then feel free to drop a couple of bucks in the tip-jar.

Post to Twitter Post to Delicious Post to Facebook Post to Reddit Post to StumbleUpon


similar posts

Steps for setting up Flash Builder to create multi-touch applications

February 26th, 2010 . by polygeek

Setting up Flash Builder to create multi-touch apps is simple for those who are familiar with Eclipse. But if you are new to this platform there can be a few spots that might get sticky. That’s why I created this short video.

Obviously the first thing you need is the AIR 2 SDK and Runtime bits. The links are provided below.

The 360|Flex conference next week in San Jose, March 7-10 is going to have a good bit of multi-touch goodness. There is a Birds of a Feather session dedicated to multi-touch along with a handful of sessions that will cover various aspects. Exciting times.

Let the multi-touching begin!

Note: Multi-touch monitor sold separately. :)

If something here has proved valuable to you then feel free to drop a couple of bucks in the tip-jar.

Post to Twitter Post to Delicious Post to Facebook Post to Reddit Post to StumbleUpon


similar posts

Forcing your Flex 4 app to scroll to the bottom of the page

February 25th, 2010 . by polygeek

I’m working on a project – AroundTheseWords.com – that has user submitted comments. When a user submits a comment I want to scroll the app to the bottom automatically. Sounds pretty easy but it gets slightly tricky.

The setup
This is a Flex 4 app where and the Application is skinned to add scrollBars. ( See post: Put a border around your scrollable Flex 4 app ). It is simple to tell the AppSkin to scroll to the bottom of the page. In the skin class just say:

scroller.verticalScrollBar.value = scroller.verticalScrollBar.maximum;

That will scroll to the bottom. But the question is when to do it. If I simply tell the skin to scroll to the bottom directly then it will do so however there might be content added to the Application after it scrolls and then I’m not at the bottom anymore.

My first thought was to set a flag – _flag_scrollToBottom – in the skin telling it to scroll to the bottom on the next updateComplete of the  <s:Scroller> component. But there is no telling how many times that event might fire. In my case it went off 4 times.  But after I scroll to the bottom I want to turn the flag off so that it doesn’t keep scrolling to the bottom on every single updateComplete.

A little hackery
This seems a little hackery but it works fine. When I set the _flag_scrollToBottom to true I also set the _flag_time to the current Date – new Date(). Now in the updateComplete event I keep scrolling to the bottom as long as _flag_scrollToBottom is true. And at the same time I check to see if more than 1000 milliseconds have expired since the flag was set. My thinking is that any updates are going to take place in much less than 1 second. Now the next time the user does something to change the height of the app the updateComplete event will fire again and it will find that more than 1000 milliseconds have passed and so now it will set the _flag_scrollToBottom back to false and then return without scrolling to the bottom. That all seems to work just fine.

Below is the pertinent code from the AppSkin.mxml file:

private function setVertScrollToMax():void {
	_flag_scrollToBottom = true;
	_flag_time = new Date();
	scroller.verticalScrollBar.value = scroller.verticalScrollBar.maximum;
}

private function onUpdateComplete():void {
	/**
	 * 	Hack: the problem here is that the 'updateComple' event fires
	 *		many times when the display is updated. For instance when
	 * 	submitting a comment it fires when the comment is rendered by
	 * 	the DateRenderer and then again when the submit comment field
	 * 	is repositioned at the bottom. So when is it actually DONE
	 * 	updating? I'm going assume that it takes less than one second
	 * 	to do all that and it's unlikely that the user will enter
	 * 	anything during that short time. So I don't unset the
	 *		_flag_scrollToBottom until at least one second has passed.
	 * 	What should happen is that the next time the updateComplete
	 * 	fires due to a screen update is that it does reset the _flag_
	 *		and then returns without scrolling to the bottom.
	 */
	if( _flag_scrollToBottom ) {
		var now:Date = new Date();
		if( now.time - _flag_time.time > 1000 ) {
			_flag_scrollToBottom = false;
			return;
		}
		scroller.verticalScrollBar.value = scroller.verticalScrollBar.maximum;
	}
}

Note: I’m using my MCP event dispatcher class to notify AppSkin.mxml that I want it to scroll to the bottom. I’m sure you’ll come up with your own technique of communicating with your AppSkin.mxml.

If something here has proved valuable to you then feel free to drop a couple of bucks in the tip-jar.

Post to Twitter Post to Delicious Post to Facebook Post to Reddit Post to StumbleUpon


similar posts

Put a border around your scrollable Flex 4 app

February 23rd, 2010 . by polygeek

Remember back in the Flex 3 days where we had to set verticalScrollPolicy/horizontalScrollPolicy to off all the time? Well, no more of that. About the only thing that gets scrollBars automatically is the TextArea. You want scrollBars somewhere else then you have to use the <s:Scroller> class.

If you would like to make your Flex application scrollable and put a border around it then all you have to do is skin the application by setting its skinClass like so:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
     xmlns:s="library://ns.adobe.com/flex/spark"
     xmlns:mx="library://ns.adobe.com/flex/halo"
     width="300" height="300"
     skinClass="skins.AppSkin" >
view source

Your AppSkin is simple. Just throw in a <s:Scroller> around the <s:Group id=”contentGroup”> and then use FXG to throw a border around the whole mess and you can call it a day.

<s:Skin
     xmlns:fx="http://ns.adobe.com/mxml/2009"
     xmlns:s="library://ns.adobe.com/flex/spark"
     alpha.disabled="0.5">

<fx:Metadata>
     [HostComponent("spark.components.Application")]
</fx:Metadata>

<s:states>
     <s:State name="normal" />
     <s:State name="disabled" />
</s:states>

<s:Scroller
     id="scroller" width="100%" height="100%"
     hasFocusableChildren="true"
     verticalScrollPolicy="auto"
     horizontalScrollPolicy="auto">

     <s:Group id="contentGroup" left="0" right="0" top="0" bottom="0" />

</s:Scroller>

<!--
Strokes are centered on the described shape.
So a width of 4 means we have to move the Rect 2 pixels
x and y and then make the Rect width/height 4 pixels less
than the actual width/height of the area we want to encompass.
Plus, we have to take into account the dimensions of the scrollbars.-->

<s:Rect x="1" y="1"
     width="{ hostComponent.width - scroller.verticalScrollBar.width - 2 }"
     height="{ hostComponent.height - scroller.horizontalScrollBar.height - 2 }">
     <s:stroke>
          <s:SolidColorStroke color="#000000" alpha="0.5" weight="2" />
     </s:stroke>
</s:Rect>

</s:Skin>

That’s all.

If something here has proved valuable to you then feel free to drop a couple of bucks in the tip-jar.

Post to Twitter Post to Delicious Post to Facebook Post to Reddit Post to StumbleUpon


similar posts

« Previous Entries    



polyGeek.com

© Copyright 2008 polyGeek.com / Dan Florio, All Rights Reserved Except Where Explicitly Stated
Web Developement Blogs - Blog Catalog Blog Directory
M2 Websites
Local Directory for Los Angeles, CA

Better Tag Cloud