« Component Pack from ILOG | Main | Using SQL with Adobe AIR »
December 31, 2007
Scrolling Text Component
Here's another example of a Flex component. This one scrolls a message within a fixed area. The message can be scrolled vertically or horizontally. You can give it a try right here:
This component shows how to use custom properties, meta data to work with Flex Builder, and overriding functions.
Click here to download the source code. The download is a Flex Builder 3 Beta 3 project - if you do not have Flex Builder 3 Beta 3 from Adobe Labs, you can open the file as a regular archive and use the source code.
Posted by pent at December 31, 2007 08:27 AM
Comments
Thanks for the component, perfect timing as my project needed this. Was doing the same effect using canvas, didn't think about using the mask.
BTW when is it better to use Label instead of UItextfield? I thought for custom components UItextfield was the prefered component to use.
Thanks
---------------
Peter: You should be able to use UITextField in this case, too. In general, if you start with UIComponent and need static text, use UITextField as it is lighter weight. I tend to use Label in example because it is a bit easier to understand and more familiar to new Flex users.
Posted by: Lordy at December 31, 2007 02:06 PM
Amazing...
Thanks
Posted by: Ivan at January 18, 2008 03:49 AM
I am relatively new to flex.. I was looking for something like this. I have a project where I would like to use your component. I am currently running Flex Builder 3 Beta 3. I have the swc included in the libs folder of my project and have the following code to create an instance:
<controls:ScrollingText text="Balaji Ramesh" direction="leftToRight" speed="2" width="100%" />
The code compiles fine but I don't see the scroller. Am i missing something here?
Thanks,
Balaji Ramesh
------------------
Peter: You also need to specify a height; the default is 0.
Posted by: Balaji Ramesh at January 19, 2008 09:33 AM
Hi Peter,
Thanks for your response. I tried setting the height but still could not get it to work. I am not sure if i am doing something wrong. Can you enable view source on the above example. Maybe that would help.
- Balaji
-------------
Peter: There is a link in the article to download the source code.
Posted by: Balaji Ramesh at January 21, 2008 06:53 AM
I did get the source code from the link and thats how i got the SWC file but what i wanted was the markup required to create the scroller. This is what i am using and i still dont see it :-( Sorry if i am being a little pesky:
------------------
Peter: If you take the sample application and replaces the constraints (left, top, right, bottom) on the ScrollingText tag with height="10%" width="50%" you should still see it working.
If that is true for you as well, then my guess is that 10% of the container's height (or 50% of the width) in your example is just too small.
Posted by: Balaji Ramesh at January 22, 2008 12:01 AM
It seems that you are missing one line for the
RIGHT_TO_LEFT moveText() function
cache[currentIndex].x -= messageSpeed;
Without that, the text woudln't scroll from left to right wouldn't go
------------
Peter: Hmm. I thought I posted the code right when I made the example of the page. I must have messed around with it a bit first. Thanks for catching that. I'll try to repost the code.
Posted by: oscar at January 29, 2008 07:14 PM
Hi, I'm getting a blank canvas, here is my application code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:comp="peter.*" layout="absolute">
<mx:Canvas id="myCanvas" width="500" height="500"
backgroundColor="blue">
<comp:ScrollingText text="Hello World" direction="rightToLeft"
speed="5" width="100%" />
</mx:Canvas>
</mx:Application>
I'm using the latest version of Flex beta 3
I created a folder 'peter' and created a new actionscript class 'ScrollingText.as' and ran it, no errors, I turned on debugging, it does go into the class and executes. . .
any ideas? thanks,
-----------
Peter: Sorry for the delay, I was on vacation. You need to do 2 extra thngs: 1) give the ScrollingText component an id (eg, id='scrollingText') and then 2) start it scrolling by doing scrollingText.start() from an event handler like
Posted by: steve at February 1, 2008 02:39 PM
How hard would it be to make the text 'clickable' (open up a new window)?
how would I do that? use an htmltext field?
thanks,
-----
Peter: You could modify the code to use the htmlText property and enclose the link in some clickable text HTML text. Then you have to listen for the LINk event on the text control itself and use navigateToURL to actually make the link happen.
Posted by: steve at February 1, 2008 02:44 PM
Good work for this component!
I'm working with Builder 2 and try to use htmlText property like you suggest to steve.
I've just replace some code like 'text' reference for 'htmlText'.
It works with a sample text and or tags but no with tag or .
Have you a idea ?
Something else : Text in my ScrollingText component doesn't do any line break when line is larger than box and content was truncated.
Is there a solution ?
Thank you and sorry for my english..
------------
Peter: I'm afraid I'm not really sure what you are trying to do. As for the line break - the component uses a Label which does not do that. You'd have to change it to a Text component and then set a specific width - that is the only way to get the line break.
Posted by: korb3n at February 6, 2008 10:55 AM
ok
Posted by: axhama at February 6, 2008 03:48 PM
Sorry for the holes in my previous post.
I was saying that when i use the htmlText property in your class to get my text, it displays fine 'b' or 'font' tags but no 'br' or 'a' tag.
For line breaks, i'll try to do with your answer. Perhaps it will resolve my other problem.
Thank you Peter.
Posted by: korb3n at February 7, 2008 03:44 AM
hello all ! i need a help i want a guidlines for scrolling a text in label box in vb 6.0.and it should have to updated automatically
---------
Peter: I'm sorry, but I don't know VB - this is my blog about Adobe Flex.
Posted by: gopinathan at February 22, 2008 11:53 PM
I'm scrolling a large font text and it looks a little choppy even at 30 fps. Is there a way to make the movement smoother?
---------------
Peter: You might try setting the two Label's cacheAsBitmap flag to true and maybe use an embedded font. In my tests I didn't notice any real improvement, but give it a shot.
Posted by: gordon at February 28, 2008 01:14 PM
This is great many thanks!
I'd like to freeze the text if it is smaller than the control. I use measuredWidth to check that but then if I call stop() the text doesn't display at all. Any way around that?
Thanks,
Alex
-------------------------
Peter: I'll have to experiment with that. Simply calling stop() does make it freeze and it still displays. I'll look into this as soon as I can.
Posted by: Alex at February 28, 2008 10:30 PM
Hi Peter,
I changed your project so it's supports htmlText and the link event.
http://biemond.blogspot.com/2008/07/flex-scrolling-text-component-with-html.html
thanks for the great example
Posted by: Edwin Biemond at July 1, 2008 04:28 PM
I've downloaded your components but I don't see how I can implement the component into a project of mine.
Posted by: Jason Wright at September 17, 2008 11:07 PM
You can either drop the source directly into your project and create a new Flex Library Project (assuming you are using Flex Builder) and create a .SWC which you can then add to your project's build path.
Posted by: Peter Ent at September 19, 2008 08:53 AM
This is awesome! Exactly what I was looking for~ Thanks!
Posted by: Ruishi at October 9, 2008 12:51 AM