PDA

View Full Version : display array item in label or text box help


fullyii
11-08-2008, 06:12 PM
Using Flex Builder 3 and asp.net

Hello I have a web service that returns Question, Answer1,Answer2,Answer3,Answer4 and CorrectAnswer.

I want to be able to display the Question in a text or label control. Once the question is visible I want to be able to display the next question when the user clicks a button.

Can someone please show me how to display the question in a textbox or label?

Any help would be greatly appreciated?


I currently have the following functions that populate a datagrid:


[Bindable]
private var myData:ArrayCollection;

private function getData():void
{
myService.FindAll("", "Question", false);
}

private function resultHandler(event:ResultEvent):void
{
myData = event.result.Tables.Table0.Rows
as ArrayCollection;
}

<mx:Label text="Hello from ASP.Net" fontSize="18" fontWeight="bold"/>

<mx:DataGrid dataProvider="{myData}">
<mx:columns>
<mx:DataGridColumn dataField="Question" />
<mx:DataGridColumn dataField="Answer1" />
<mx:DataGridColumn dataField="Answer2" />
<mx:DataGridColumn dataField="Answer3" />
<mx:DataGridColumn dataField="Answer4" />
<mx:DataGridColumn dataField="Correct" />
</mx:columns>
</mx:DataGrid>

fx.barrett
11-08-2008, 07:40 PM
You should add a RESULT event listener to your web service so you can react once Flash got the result. Once that's done, you should just simply update the label ( or text field, it really doesn't matter in this case ).

When you are displaying simple data such as this it really doesn't matter if it's a text field or label. But if you ever decide to do more than just display plain text then you should definitely go with a text field ( or even DataGrids and more advanced components ).

fullyii
11-08-2008, 08:57 PM
Ok I am very new to Flex so forgive me for my lack of knowledge. I have a function "getData" that stores the web service data in a myData:ArayCollection. Is there a way to access the data and display the data in the label? If so please share a quick example.

If this can be done then the amount of network traffic would limited.

I tried something like this but only able to retrieve Object Object as the result.

<mx:TextArea id="Question" text="{myData[0].toString()}" />

CyanBlue
11-09-2008, 09:16 AM
What purpose does your poll serve??? I don't get it...

fullyii
11-09-2008, 03:20 PM
I am very new to this forum and Flex and I am not getting very many responses to my question so I wanted to know if I am even in the correct place and or if this is a question that has a possible solution. At this point I do not have a solution to my question so I am beginning to think I am in the wrong place.

One would think it would be very simple to display an array item in a label but it appears that this is not the case.

fullyii
11-09-2008, 11:49 PM
Does anyone have an example of how to populate a textbox or label from a web servervice?

fx.barrett
11-10-2008, 12:00 AM
You populate it the same way you'd populate it without a web service... the only difference is that instead of having the data, you must wait for the web service result event and then pass the desired data...

Not really sure what example you want... instead, search for a Beginning Flex 3 book and learn the basics.

People aren't answering because what you are asking is ass simple and it might just not be worth the few seconds to post the answer ( especially when your question is ambiguous and we can only guess an answer from what you've posted ). You are obviously lacking on the basics so instead of jumping into the unknown, sit down and read up...

fullyii
11-10-2008, 12:07 AM
ok thanks for the reply. I am going through and learning the basics now. I guess one has to become an expert before he can get a simple question answered. Sorry to waste everones time!

fx.barrett
11-10-2008, 12:46 AM
ok thanks for the reply. I am going through and learning the basics now. I guess one has to become an expert before he can get a simple question answered. Sorry to waste everyone's time!
Actually... One should never post intermediate to advanced code and then ask an extremely simple question. Because others can deduce only one thing: "if he can't even assign simple text to a text field then obviously, he wasn't the one who wrote the code he posted.... so it would be a pain in the ass to explain something to someone who has absolutely no idea what he is doing."

Not that your code was advanced or intermediate, but since you posted something on web services and you even have a DataGrid there but you don't know how to assign text to a text field then something is obviously wrong...

fullyii
11-10-2008, 12:59 AM
Yes you are correct - I am going through a few tutorials that i found online. I wrote the web service in vb.net and used the flex tutorial code to populate the grid. I am going to go back and start with the basics and see if I can get a better understanding. I hope that I did not offend you and apologize for my lack of understanding of the basics. I will dive into a few easier tutorials and check back with this at a later time.

Thanks for your honesty and pointing me in the right direction.