At the request of Jose Carlos Fonseca, here are some explanations and details of parts of my system code used in real estate, so help him and I can help more people interested.
Q: 1.Na front page a picture emerges "loading" as indeed are you doing?
A: 1. The loading effect is achieved through the replacement of "loader" normal flex by an image, you can see here http://www.onflex.org/ted/2006/07/flex-2-preloaders-swf-png-gif- examples.php where you can find gif, png, swf and examples with source code. Just copiares to the folder of your application and <mx:Application …> colocares preloader = "preload.CustomPreloader." I made some small deployments based in this example, but if we use works well in it.
Q: 2.Pagina the login: effect of error, "checking log" and the blue bar
A: 2.The blue bar is a progressBar:
1: <mx: ProgressBar visible = "false" x = "112" and = "175"
2: labelPlacement = "left" label = "" width = "187"
3: indeterminate = "true" showEffect = "Fade ()" hideEffect = "Fade ()"
4: id = "progressStatus" />
that is activated (progressStatus.visible = true;) when the initial request to check the log in remoteObject (send) and when you get off the response of remoteObject (result). (progressStatus.visible = false;)
when receiving the result (not, the user and pass not match) is the following:
blurRed.target = panelLogin;
blurRed.play ();
panelLogin where is our panel of login and blurRed is the following effect:
1: <mx: Glow id = "blurRed" duration = "700"
2: alphaFrom = "1.0" alphaTo = "0.0"
3: blurXFrom = "0.0" blurXTo = "20.0"
4: blurYFrom = "0.0" blurYTo = "20.0"
5: color = "0 × 990000" />
As for checking login is the same system as above, or off the progressStatus since the Flex has not yet implemented the event with a remoteObject progress.
Q: 3.Pagina home: effect on the buttons on the left side
A: As for the buttons on the left side, the effect is the same panel of the error log, the effects are:
1: <mx: Glow id = "blurBlueIn" duration = "700"
2: alphaFrom = "1.0" alphaTo = "0.0"
3: blurXFrom = "0.0" blurXTo = "20.0"
4: blurYFrom = "0.0" blurYTo = "20.0"
5: color = "0 × 900aeef" />
6: <mx: Glow id = "blurBlueOut" duration = "700"
7: alphaFrom = "0.0" alphaTo = "1.0"
8: blurXFrom = "20.0" blurXTo = "0.0"
9: blurYFrom = "20.0" blurYTo = "0.0"
10: color = "0 × 00aeef" />
and the button just called them in mouseOver mouseOut events:
1: <mx: Button width = "85" height = "73" label = "button ADD" id = "add"
2: icon = "@ Embed (source = 'imgs / Home_add.png')" = x "10" and = "91"
3: fillColors = [# 000000, # 000000] "fillAlphas =" 0 "borderColor =" # 525151 "
4: color = "# FDFBFB" themeColor = "# 535C75" textRollOverColor = "# 2667B0"
5: useHandCursor = "true" mouseOver = "(buttonOver (add))"
6: mouseOut = "(buttonOut (add))" click = "(changeTo ( 'bsf1'))"
7: buttonMode = "true" />
where you have: the function buttonOver (id_do_botão) and buttonOut (id_do_botão):
1: private function buttonOver (a: Button): void (
2: blurBlueOut.target = a;
3: blurBlueOut.play ();
4:)
5: private function buttonOut (a: Button): void (
6: blurBlueIn.target = a;
7: blurBlueIn.play ();
8:)
and you made your purposes
Q: 4.Como added a photo in BD?
A: The photo is inserted through the php via amfphp in Flex are only selected the photos and sent by post to a script upload.php dealing with the transmission to the server, and return the locations of the photos that are stored in an array, where ends to send all the pictures, is called a function of remoteObject that guard the paths of the photos in the database (I chose to use relative paths instead put the picture directly in the database, already the pictures can be of great size what would fill the database).
As the system of uploading, you can see here a system similar to what I did (with code):
http://weblog.cahlan.com/files/file_uploads/FileUpload.html
where the upload.php will be something like: http://www.msdevstudio.com/mywork/upload.rar
Q: Now outside of your application, I have a table with several items and want to appear on one page each as a button, it is possible? And in the case of this page have a default number of buttons how to do paging?
A: Now the monster of responses (note I wrote this without testing, you must change many of the camps, but the essence is there:)
Part I: Buttons on each element of the "table"
As for the buttons, you can put in each line of datagrid or any element of a listing any other component, being the most common, checkbox, listbox, button or radioButton, ve this:
http://www.returnundefined.com/files/ItemRendererExample/ (source code)
http://www.adobe.com/devnet/flex/quickstart/using_item_renderers/
even similar to what should want:
http://axel.cfwebtools.com/… / UsingTheItemRendererWithADataGrid.html
These links have the view source assets.
Part II: And in the case of this page have a number of buttons predefinindo how paging?
Qaunto to make the layout, it largely depends on the type of system you have, if you can limit php mySql (LIMIT) to the listing only what you want, just create a variable publishes guardares for the initiation of the listing and another with the number of entries per page:
1: public var start: Number = 0;
2: public var porPagina: Number = 10;
3: / / to be called the Remote object, you have to say to php to build the request sql with the limitations.
4: / / flex for example in the button and following up the call to the staff goPag ( "following"), or goPag ( "up"), (depending on the button.)
5: private function goPag (where: String): void (
6: if (where == "following") (
7: start = start 10;
8:)
9: if (where == "up") (
10: start = start-10;
11: if (beginning <= 0) beginning = 0;
12:)
13: remoteObjectBusca.funcaoBusca.arguments.inicial = start; / / reset the values
14: remoteObjectBusca.funcaoBusca.arguments.porPag = porPagina; / / reset the values
15: remoteObjectBusca.funcaoBusca.send ();
16:)
where the remoteObject will be something like (amfphp):
1: <mx: RemoteObject id = "remoteObjectBusca" destination = "amfphp" source = "servico.class">
2: <mx: method name = "funcaoBusca" result = "(lidaDados (event))">
3: <mx: arguments>
4: <initial>
5: ( "0")
6: </ initial>
7: <porPag>
8: ( "10")
9: </ porPag>
10: </ mx: arguments>
11: </ mx: method>
12: </ mx: RemoteObject>
and where the function of the remote object in php receive these parameters and return the matrix of data (the Object):
1: function funcaoBusca ($ original, $ porPag) (
2: if (! Initial | | $ initial == NULL) $ original = 0;
3: if (! PorPag | | $ porPag == NULL) $ porPag = 10;
4:
5: $ con = mysql_connect ( "host", "user", "pass");
6: $ sel = mysql_select_db ( "Bdados");
7:
8: $ sql = "SELECT * FROM` `tabelaDados LIMIT." $ Original. "." $ PorPag;
9: $ res = mysql_query ($ sql);
10:
11: if ($ res) return mysql_fetch_array ($ res);
12: else return "Error";
13:)
only then we must create in the flex funçâo to read the data:
1: [Bindable]
2: public var dadosBusca: Object;
3: pivate function lidaDados (event: ResultEvent): void (
4: if (event. == Result "Error") (
5: / / error search data
6:)
7: = else dadosBusca event. The result Object;
8: / / From Here you have the data available in variable dadosBusca
9: / / for access to each element uses dadosBusca [line]. CampoDaBd;
10:)
Note: This code of the last answer was drawn up without being tested, I do not know if contains some errors .. but just test, I do not know if this would be it wanted.
Well, I think that could explain everything .. you can understand?
Put the answers in a new post, since it was a huge response, and thus can help more people.
Abraço.









44 Comments
Hello,
Sorry, only now respond, but I was out for a while at work and only went back ontém.
Thank you for the help. And that speed of response. Thanks again.
In answer to question 4 (As an added picture in BD?), To mention a link, to have been analyzing the code, but it gives me always "IO ERROR." I do not know how to use the upload.php.
Aid me?
A hug.
Jose Carlos Fonseca
Fafe - Portugal
In principle the upload.php I gave to download should work without any change, there are the links that make reference to upload.php are well:
private const _strUploadDomain: String = "http://codycodingcowboy.cahlan.com/";
private const _strUploadScript: String = _strUploadDomain "files / upload.php";
and the directory where the runs. php should have the directory myFileDir since in such upload.php is:
$ file_path = $ _SERVER [ 'DOCUMENT_ROOT']."/ myFileDir ";
if after those findings continue to provide error, indicates whether I made some changes to the code to "investigate" better.
cumps.
Hello John,
In fact was not upload.php on the directory and was not sure the directory. After resolve it no longer gives me error. This confirms the upload the image and sends it to the place. However the verification if the image is not already there. I will try to vêr where is the problem.
In bd guards the way the whole picture, right?
Now another question, (hopefully not boring !!!).
As the record show 1 bd textinput without being directly in a datagrid?
Obrigadão for help.
You have been fantastic.
A hug.
Jose Carlos Fonseca
Fafe - Portugal
Yes, in the database guardo the path of the image as many images and would overburden the database.
to show a record in the database directly in the text field can do the following, imagine the following function (which receives data from remoteObject):
imagine that your remote object returns (example in php amfphp)
<? PHP
dev function () (
/ / example 1
Return "Hello";
/ / example 2
$ data [ 'name'] = "soares";
$ data [ 'first name'] = "Julie";
return $ data;
/ / example 3
$ data [ 'antonio'] [ 'name'] = "doener";
$ data [ 'antonio'] [ 'age'] = "19";
$ data [ 'Pedro'] [ 'name'] = "read";
$ data [ 'Pedro'] [ 'age'] = "25";
)
?>
private function lidaDados (ev: ResultEvent): void (
/ / example 1, receives only one variable:
meucampo.text = ev.result
/ / example 2, receives an array of variavels:
meuCampo.text = ev.result.nome; / / returns soares
meuCampo.text = ev.result.prenome; / / Julie returns
/ / example 3, receives a "matrix" of arrays:
meuCampo.text = ev.result.antonio.nome; / / returns valeria
meuCampo.text = ev.result.antonio.idade; / / returns 19
meuCampo.text = ev.result.joao.nome; / / returns read
meuCampo.text = ev.result.joao.idade; / / returns 25
)
To facilitate this process, creates a variable bindable:
[Bindable]
public var DadosRo: Object;
and after the function that receives data from the RO, raises
DadosRo = new Object ();
DadosRo = ev.result the Object;
and hence their data can be accessed from this variable in any part of your code, and will be updated whenever the remoteObject is called.
In the example 3:
instead meuCampo.text = ev.result.joao.nome;
could use:
meuCampo.text = DadosRo.joao.nome;
It pra understand?
Abraço.
Well, I do not know if you have followed my series of tutorials (http://msdevstudio.com/blog/2008/04/08/adobe-flex-a-partir-do-zero-parte-iv/) but in the fourth exemplifico a bit part of the communication system with a backend in php, perhaps you can help us better understand some details of Flex.
John Good,
Simply brilliant. It worked direitinho.
Yes! I have followed all your tutorials, are more. If you were not concerteza the learning of flex would be more time consuming. Big help, Thank you!
(there comes the flat!) Another question, I have a viewStack to where each item is a component. These components are activated by a button, which happens after visiting once, next trip does not refresh.
It is possible to circumvent this?
If you wish, you can add my email to IM.
Thanks again.
Jose Carlos Fonseca
Fafe - Portugal
Carlos, excuse only answer now .. I have been a little busy with working: foot is perhaps therefore not clear their doubts, if the code is not put there very long .. but try to explain further ..
a hug.
Hello John, now you for answers and you do not have to apologize.
EStive to review the code and I think I have discovered the error.
However I would ask you another question, I am trying to do something that will have access through the login. How do you show the ecrã1 to the administrator, the ecrã2 to the user, and so on. We have tried, but I think I am still green in flex.
Thank you.
A Abraço.
Jose Carlos Fonseca
Fafe - Portugal
Carlos Well, you can do this in 2 ways, now depends on whether or not consumers using a backend (php, java, etc. ..)
Without Backend.
The solution can go through definires a variavél overall, or declaras the variavél, for example
var admin: Boolean = false;
Then, just when verificares always this variable is sought access to part of admin.
The ideal is separares your application by at least 3 states; Login, Admin, User
Then just make the log, and the roles that validates the login definires the variavél admin = true, and change their pro state, in this case currentState = "Admin", or if user, admin = false; currentState = "User";
Another way to do this, is using a backend in php for example, and make use of sessions, to verificares if the user is identified as admin or not… but it is a bit more extensive, but if you see what is the best way, says I do you a small example.
It would be what we wanted?
Abraço.
Hello John,
In fact the idea would create a backend in php and use sessions. Arranjas me an example.
Thank you.
Abraço.
Jose Carlos Fonseca
Fafe - Portugal
Hello John,
As your Real Estate System to the login box is not as a popup not. You use yourself states? I tried to do this, but the box does not appear from above and can not make the final effect.
In applying what I am trying to do is something like:
-- Do I sign in, enter into various screens and I out without closing the browser. When you sign in again enter the last screen and I was not in what is scheduled to appear and the effects are only made the first time.
-- And if you're within the application and make F5 (refresh) comes out and asked to sign.
This is normal? Grants for contronar.
Thanks for your help and patience.
A hug.
Jose Carlos Fonseca
Fafe - Portugal
Carlos Well, the initial effect is a simple panel, which is created on top of the application with visibility = false; started after the end is shown.
The final effect is a simple mx: Move (as the original), both with easingFunction = Elastic (mx.effects.easing.Elastic) and then visibility = false; ends when the effect (you can know when the effect ends with a eventListner the end, something like efeito.addEventListener (EffectEvent.EFFECT_END, funcao_que_esconde_o_panel);
in function:
private function funcao_que_esconde_panel (evt: EffectEvent) (
painel_login.visibility = false;
efeito.removeEventListner (EffectEvent.EFFECT_END, funcao_que_esconde_o_panel);
)
Do this with events, you should remove the eventListners…
When laps to make the sign again, the function that checks the validity of the log, it indicates to return to the state you want to alert. this.currentstate = "StateEntrada";
To make the F5 is normal that happens, what you can do is with this session, check this once in the entry in the log, and if the session is valid direct the State vai he wanted, showing no sign of the panel, already that the session is held when loading in the F5. This end of the week I should not have much time to get you an example, but so can I do.
Good afternoon John,
You can give me a hand?
After entering into some textinputs, wanted the data arise in a datagrid without record in BD. And write to the BD through a button, record everything that is in the same DataGrid.
Thank you.
Carlos, the advice is to create a ArrayCollection, and work all your data on it, which serves as both dataProvider for dataGrid, and to then send to the database.
I have an example in the blog that explains how a arrayCollection can serve to work with data in the database.
See: http://msdevstudio.com/blog/2008/03/25/flex-datagrid-operaes-no-dataprovider/
On the record in the database, send that arrayCollection as parameter for the remoteObject.
Ve an example, if do not achieve, puts your doubts
Abraço.
Hello Mario,
I have a arrayCollection with data.
No remoteObject would be?
() data
where "data" is my arrayCollection.
And in PHP how it would be to insert in the table since the arrayCollection is structured as follows:
data = [ "campo1, campo2, campo3"
"campo3, campo4, campo5"]
Thank you!
Jose Carlos Fonseca
Fafe - Portugal
Good!
But then, considering the following roles in php
function inserts ($ data) (
$ sql = "INSERT INTO` table `(` campo1 `,` campo2 `,` campo3 `,` campo4 `,` campo5 `,` `campo6) VALUES ( '$ data [0] [campo1]', '$ data [0] [campo2] ',' $ data [0] [campo3] ',' $ data [1] [campo4] ',' $ data [1] [campo5] ',' $ data [1] [campo6] ') ";
if (mysql_query ($ sql)) return "ok";
else return "error". mysql_error ();
)
then simply call the roles in the remote object, something like a method well in
mx: remoteObject rest…… as target, detination ..>
mx: method name = "insert" result = "insereRes (event)">
MX: arguments>
data>
() data
/ data>
/ MX: arguments>
/ MX: Method>
/ MX: remoteObject>
ps lacking the "<" at the beginning of each line, because to put the code has to be that way!
This should solve your question…
A arrayCollection is treated as an array of arrays in php, or the typical matrix (scale of data) and a simple array is treated as array…
Esperimenta and it went like….
Hello John,
I was absent for a few days so it is only now that answer.
It worked impcável! Thank you.
I am trying to control the camps textinput before sending the data to the datagrid. Only I lack a test that I am not achieve.
Check if you enter the textinput already exists in the datagrid. You can give me a hand?
Thank you.
Jose Carlos Fonseca
Fafe - Portugal
private function exists (text: String): Boolean (
Var existeV: Boolean;
existeV = false;
for (var x: int = 0; x <meuDataProvider.lenght; x ) (
if (String (meuDataProvider [x]. campo_a_comparar) == text) existeV = true;
)
Return existeV;
)
to verify just using
if (there (String (meu_text_imput.text)) = true) (/ /) exists
else / / does not exist.
Note that not tested, but should work without problems.
It would be this?
Abraço.
John Good,
Perfect! My mistake was not going on to String on condition IF.
Another request for help:
I have a hierarchical data tables, or equipment-> brands-> models
EX: Monitors -> ELOTouch -> 15 Polgadas
Create a screen to show these data the better, I think, would be a TreeControl datagrid.
In TreeControl appeared Monitors -> ELOTouch -> 15 Polgadas and dataGrid the various data of their equipment (number of series, registration, date, etc.)
It will be very hard to do this? Did you have any example where I can guide? Not yet found nothing in the net.
Thank you.
Jose Carlos Fonseca
Fafe - Portugal
Well, actually the examples which are are all in MXML or XML also why never worked with the Tree's, but look at this example:
http://blog.flexexamples.com/2007/12/03/using-an-array-as-a-data-provider-in-a-flex-tree-control/
as dataProvider has an array of objects, this can be recreated in action script and then just have to mandar the output of php in the same format, which you are already mandar properly for the flex, must serve without problems, but you have to build the php in your data as objects…
$ array [ 'data'] -> name = campoCategoria;
$ array [ 'data'] -> content [0] -> value1 = Campo1;
$ array [ 'data'] -> content [1] -> value2 = Campo2;
but if I find any example I notice….
Abraço.
Neither of respect, ve here:
http://www.adobe.com/devnet/flex/quickstart/working_with_tree/
near the end of the page is the creation of a dataProvider for the tree, just in php using the same data structure.
the source is:
http://www.adobe.com/devnet/flex/quickstart/working_with_tree/src/TreeKeepOpen/index.html
Abraço.
Okay, now I see and then say something.
Already now: the expression
if (String (data [x]. field) == text) existeV = true;
the word field is a variable (string) which receives 3 values. As is not working as it does not belong to field data. How to solve?
Abraço.