Lean and mean table for AIR mobile - actionscript-3

I'm sure a lot of people need this, but so far I have not been able to find a good solution.
Environment: AIR app for iOS and Android created with Flash CS6.
What I'm trying to do: Display a table (5 columns, 200 rows). Nothing fancy, just text data. The table should be sortable and scroll smoothly in response to swipe gesture.
The DataGrid component is too "heavy" and not recommended for mobile. Is there a simple solution for this?

For table display (even fancy) I would use the StageWebView, of course if you can afford to not be able to overlay anything over it.
Quick Sample below:
webView = new StageWebView();
webView.viewPort = new Rectangle(0, 44, 480, 756);
webView.loadString('<html><head><style type="text/css">tr:nth-child(odd) { background-color:#eee; } tr:nth-child(even) { background-color:#fff; } .header_button { width:100%;}</style></head><body><table width="200" border="1"><tr><td><input name="Name" type="button" value="Name" class="header_button"></td><td>Id</td></tr><tr><td>Mark</td><td>0</td></tr><tr><td>Bob</td><td>1</td></tr></table></body></html>');
webView.stage = stage;
you should read through documentation as loadString is pretty limiting:) to see all possible ways of using this class, but the idea should by planted in you by now:) e.g. CSS, JQuery etc. can be used, and scrolling is really fast:)

I haven't tried them yet, but Mad Components (technically it's the Extended Mad Components lib) has a UIDataGrid class.
Other than that, since your grid/table is only intending to display text, you might want to give the components from Adobe a try. Their grids are flexible, and as a result can be "heavy".
Since you only want to render text, you won't pay the price of trying to render heavier objects (check boxes, buttons, etc) inside the grid. The performance (when only rendering text inside the grid) may be acceptable.

Forget the Flex DataGrid, even with static text you won't get acceptable scrolling performance (I got about 5fps for a real time data grid).
The way to go is a normal List with a custom LabelItemRenderer and a button group for the header. You can make the renderer look like a grid very easily.
I haven't tested Alex Harui's list based grid, but it should work out of the box. If not, you should get the idea. Just roll your own AS3 based renderer and performance should be over 25fps even with fast scrolling. I get around 30 on an iPad2.

Related

how to actor render to Particular posistion without any inputprocess

i'm new to libgdx, I'm trying to make a sprite move to particular target. I can make the sprite move perfectly in x position. i`d move to target position without inputprocess like a enemy. I've tried a few different things but at this point its just guessing and checking.
o(actor) render to target from any position of screen.
/*
o((qx,qy)actor)
|
|
v
((lx,ly)actor)o--->target(tx,ty)<------o((rx,ry)actor)
*/
pls helpme ...
I suggest you take a look at Universal Tween Engine. It's perhabs some overkill to just linealy progress a value across time but it will handle all the things you need. Just read the GetStarted page on the GoogleCode project of it to learn the basics.
Also, you can run a demoApp that showcase it's potential.
Here it's in HTML5
Here it's in Desktop
And here it's in Android
All three are done in LibGDX by the way.

Changing States does immediate make changes in Flex

I have an application that switched between different graphs in Flex. Each graph is it's own state. In the MXML I have it set so that the source of the image change when the state changes:
<s:Image id="chartImage"
source.all="{ callImages.all }"
source.classA="{ callImages.classB }"
source.classB="{ callImages.classA }"
/>
I have buttons that successfully change the images. However, I have a small bug which occurs because after the line
this.currentState = chartName;
My code expected the graph image source to be changed, however the actual change to the s:Image element doesn't appear to happen until after the function ends and the screen updates, I assume. So when it grabs chartImage.height, it uses the old one from the state I just left.
Is there a way to have it get the new image (and thus it's dimensions) so I can do calculations with those dimensions on the next line? So far, chartImage.height returns the height from before the state change, but it is different after the function executes.
I could run a timmer after a fraction of a second then execute the lines there, and it would work. However, I'd rather tell it to render the screen and then continue my code. Is this possible? It just seems more elegant.
Is there a way to have it get the new image (and thus it's dimensions)
so I can do calculations with those dimensions on the next line?
Each Flex component must go through it's own validation cycle, which is built on top of the Flash Player's rendering mechanism. There are some great posts out on this, if you perform a Google search for the Flash/Flex Elastic Racetrack.
However, you can force a component to run through it's validation methods in a linear manner by calling the validateNow() method.
It is possible--especially if you have a state transition--that the properties on your Image have not changed yet after you set the currentState variable.
You generally can't change the source of an image in Flex and then immediately check ("on the next line") it's height — the exception might be when the source is a raw bitmap, but even then Flex's layout framework will vary depending on different factors so I wouldn't rely on this.
This is the classic problem with Flex: the beauty (and misery) of the framework is that it progressively renders it's changes to maximize the responsiveness of the app. Google "flex component life cycle" for a ton of resources about the details of this process.
There are a couple of ways to deal with this. Usually you'll want to use binding expressions, since they are designed for exactly this reason: asynchronous layout changes. Don't overuse them but they are a solid tool to keep the codebase simple and flexible.
You can bind to the height of a SparkImage via mxml:
<s:Image id="chartImage" />
<s:Label id="debugLabel" text="{ 'Height of chartImage: ' + chartImage.height }" />
but if you need to run logic I'd recommend using the BindingUtils (in the script block):
import mx.binding.utils.BindingUtils;
protected function someOtherFunctionBlock():void
{
BindingUtils.bindSetter( handleHeigtChange, image, "height" );
}
protected function handleHeigtChange( value:Number ):void
{
// Deal with value change
}

Code for A Graphical User Interface window

How would someone go about coding a 'window'? I'm starting to make a GUI, and I want to learn how to code one. One that can be skinnable, and one that actually loops and creates itself at runtime. I understand that this might be a bit vague, so I'll add details.
One that actually 'creates' itself. Most GUI tutorials I've looked on depends on an 'image' that just gets added on the screen. I want to be able to use skins in my windows. One where my 'skin' is just a collection of 'borders'. Then when I insert window.create(50,50) where 50,50 is my height, width, It would just create that window, following the skin.
I understand that it probably follows just like when a language draws a rectangle, it just follows a different set of rules (maybe?). However, for all my Google-fu skills I cannot find a tutorial that teaches me this.
Please Help. I didn't include the language I used as you can see, because I believe I just need to know how to create one. Anyway though, I am using Actionscript 3. A tutorial would be just fine, or even A SINGLE CLASS THAT HAS THIS FUNCTIONALITY, I'll just study the code. Or if you know one, maybe a whole book about GUI and programming it :D
Pure As3.0 GUI coding is quite troublesome. I try to Googling, but not come out well. anyway for my case, i generate using a SWC, and Class Mapping and Customizing. but i'm not sure best way. in other way i use a bit101 library. this is gives me want Window, Charts, Componets easily of high abstraction. see the below image.
It can be pretty hard and complicated to do, or very easy, it just depends on how flexible your solution should be. You need firstly to design a structure of your program and approach to the problem.
I like to go from the image of how it should look like from API point of view. I think I would create a GUI element like this:
var wholeGui:MyGUI = new MyGUI();
var window:IGuiElement = new GuiWindow(dataObject, skinObject);
wholeGui.addElement(window);
So what would you need?
1) Object that would manage all GUI elements. Why? Simply because your GUI elements shouldn't be destroyed by themselves if user will click "X" on your little window. The wholeGui object would manage them and listen for any events including those that would destroy them. You may consider creating custom events for interaction between the wholeGui object and your window object if this interaction is going to be complicated.
2) Interface for your GUI objects. Some problem here is that AS3 actually doesn't have interface for Sprite, and you would like to interact with it like with extended Sprite. The workaround here is to have in this interface a declaration like this:
function asSprite():Sprite;
And your implementation in GuiWindow would look like this:
public function asSprite():Sprite {
return this;
}
And your GuiWindow class should extend Sprite of course. Then you would have access to it's Sprite properties and methods by writing for example: window.asSprite.startDrag();
This interface should give you abilities that you need to operate on your GUI element.
3) Class for your GUI element, in this example GuiWindow.
4) Class for your data that would be injected into your element. If you would load data dynamically, and from some location, you would need to deal with the situation when no data can be provided - but that logic would be inside your window.
5) Class for your skin - so you would be able to dynamically create a skin object and use it to create your window in a way you want.
That's just few thoughts to consider.
PS. It may be good idea to fill GuiWindow object with data AFTER creating it, and not in constructor, as you would be able to visualize loading process then.

How to add RichEditableText of TextArea using only ActionScript

My head is spinning from two days of trying to find an answer to this seemingly simple question.
I'm developing a Flex/AIR application built entirely in ActionScript -- there's no MXML beyond what was originally auto-created.
I need to dynamically generate some kind of editable text-field with high control over formatting. The TLF text fields all seem great, except that I can't get any of them to render on the screen. Due to the nature of the application, they have to be inside a MovieClip, but since I've read that everything must be a descendant of UIComponent, I use UIMovieClip, which is AddChild'ed to the stage.
I'm about to go crazy here, the whole application is in jeopardy over this. I CAN NOT use MXML, and all the 10,000 examples on the internet are MXML. I need to generate these dynamically. I need to generate upwards of 50 fields under one movieclip based on database data. There's no way to hardcode that with MXML. Please don't suggest to change this. The GUI is very specific about this, and it's the right GUI.
In two days of searching, I can't find a single example in ActionScript, only MXML. I've tried everything that smelled like an example.
Is there some obvious general pointer I'm missing? I'll be happy to post code, but it doesn't make sense because I've been through so many examples.
Does anyone have the simplest possible code for creating any kind of TLF text editing field in ActionScript only (zero MXML), which is then added to a MovieClip or UIMovieClip, which is added to the stage of a desktop AIR application?
I will greatly cherish any help here.
Best,
Per
This should get you started:
//create your TextFlow component
var textFlow:TextFlow = new TextFlow();
var p:ParagraphElement = new ParagraphElement();
var span:SpanElement = new SpanElement();
span.text = "hello world";
p.addChild(span);
textFlow.addChild(p);
//create a Sprite that will contain the text
var textBlock:Sprite = new Sprite();
//create a controller for compositing
var controller:ContainerController = new ContainerController(textBlock);
//set the size of the composition
controller.setCompositionSize(100, 200);
//make the controller control the TextFlow object
textFlow.flowComposer.addController(controller);
//update the composition
textFlow.flowComposer.updateAllControllers();
//add to the stage
addChild(textBlock);
About the size: it is important you use setCompositionSize() instead of the Sprite's width and height properties.
Using addController() you could spread the text over several Sprites. Each Sprite would have its own ContainerController, but all would share the same FlowComposer which would calculate the composition.
warning : using TLF like this can be pretty complicated. Above code is the bare minimum to get things running. I do not know your requirements, but you'll probably hit a few other roadblocks along the way. You have to ask yourself this question: are you really willing to drop all the built-in features of TextArea? It might cost you months of development to get things right, depending on the requirements. You still may want to reconsider your architecture...

Unknown error AS3

Well, it's not an error, actually. I have wrote a game. There is only one keyframe on the main timeline (I don't mean one layer, there are lots of them, just like different MovieClips). Currently, I'm not using TextField anywhere, but I want to, because I need to display score on the screen. When adding TextField through Flash CS5 and naming it, when compiling, unknown window appears, you can see it on the picture. Not quite sure what it means. When clicking OK, window disappears but instead of my program there are three dots on the screen, you can see them also. I have no idea, neither of what is this, or how to fix it. Any hints? Thank you in advance :)
By the way, on one of the pictures, you can see what the game should look like. And as I said, it does, until I add some TextField to it.
it seems that you're using the TLF (text-layout-framework) in your textfield by accident.
this is a RSL (runtime shared library) that the flashplayer has to load before it can show your content. (and i think the dots are some kind of preloader that adobe puts in there ...!?)
but you don't need the TLF, you can just use a simple TextField.
select your score-textfield and choose "classic-text" in the properties window ... think that'll remove the TLF from your project. (if you have more than one TextField, check every one of them for "TLF text" and change it to classic).