Ontem tive um pequeno problema a desenvolver parte de um aplicativo (o frontend para o meu sistema imobiliário) onde necessitava de saber onde estava a correr o aplicativo, bem como o caminho relativo do servidor, já que tinha que obter varios caminhos para fotografias onde esses caminhos poderiam variar. Yesterday I had a small problem to develop part of an application (the frontend system for my property) where needed to know was where to run the application, and the path on the server, since it had to obtain multiple paths to where these photos paths could vary. Ou seja, precisava de saber o caminho onde as minhas fotos se encontravam, já que se estivesse a correr apenas em, por exemplo www.msdevstudio.com/immo/frontend/ saberia exactamente onde encontrar as minhas fotos, que estariam no caminho absoluto www.msdevstudio.com/immo/frontend/imgs mas o problema seria se mudasse de servidor, as fotos poderia passar a estar em www.meuserverto.com/imgs e aí teria que programar o flex para ir procurar as fotos a este caminho… mas dizem voces, porque não usar apenas source=”imgs/imgExempo1.png” ? In other words, it needed to know the way in which my photos were, as if he were to run only in, for example www.msdevstudio.com/immo/frontend/ know exactly where to find my pictures, that would be the absolute path www .msdevstudio.com / immo / frontend / imgs but the problem would be changed if the server, the photos could become one that is in www.meuserverto.com / imgs and there would have to flex the plan to go look at the photos this way… but you say, why not use only source = "imgs/imgExempo1.png"? pelo simples motivo que necessito de juntar algumas fotos a um HTML text, bem como dar a possibilidade do user mudar a directoria das imagens e os caminhos relativos. for the simple reason that I need to add some photos to an HTML text, and allow the user to change the directory of images and relative paths. (não encontrei outra solução para já…) (I have found another solution for now…)
Bom, dei de caras com as propriedades deepLink, que podem ser obtidas atravéz do browserManager/URLUtil, por isso fiz um pequeno exemplo que podem usar nas vossas aplicações, copiando o contudo do arquivo que disponibilizo em baixo para a raiz da vossa aplicação, depois basta fazerem o import na vossa aplicação: Well, I gave the guys with the properties deepLink, which can be obtained through the browserManager / URLUtil, so I made one small example we can use in your applications, however copying the file that the offer down to the root of your application, then just do the import in your application:
import com.msdevstudio.urlUtils; Import com.msdevstudio.urlUtils;
São então disponibilizadas as seguintes funções: They are then made available the following functions:
getPort():String getPort (): String
getProtocol():String getProtocol (): String
getServer():String getServer (): String
getDoc():String getDoc (): String
getTodo():String getTodo (): String
getPath():String getPath (): String
onde para receberem os respectivos elementos devem usar: where to receive their elements should use:
1: var util:urlUtils = new urlUtils(); 1: var useful: urlUtils = new urlUtils ();
2: //tomando como exemplo o link: http://msdevstudio.com/immo/backend/backend.html 2: / / taking as an example the link: http://msdevstudio.com/immo/backend/backend.html
3: 3:
4: //buscar nome do servidor: 4: / / fetch the server name:
5: var nomeServidor:String = util.getServer(); 5: var nomeServidor: String = util.getServer ();
6: //devolve: msdevstudio.com 6: / / returns: msdevstudio.com
7: 7:
8: //buscar protocolo 8: / / fetch protocol
9: var protocolo:String = util.getProtocol(); 9: var protocol: String = util.getProtocol ();
10: //devolve http 10: / / returns http
11: 11:
12: //buscar porta 12: / / fetch door
13: var porta:String = util.getPort(); 13: var door: String = util.getPort ();
14: 14:
15: //buscar url completo 15: / / url seek full
16: var urlCompleto:String = util.getTodo(); 16: var urlCompleto: String = util.getTodo ();
17: //devolve http://msdevstudio.com/immo/backend/backend.html 17: / / returns http://msdevstudio.com/immo/backend/backend.html
18: 18:
19: //buscar caminho relativo 19: / / fetch relative path
20: var caminho:String = util.getPath(); 20: var path: String = util.getPath ();
21: //devolve http://msdevstudio.com/immo/backend/ 21: / / returns http://msdevstudio.com/immo/backend/
22: 22:
23: //buscar o nome do portador do swf 23: / / fetch the name of the bearer of swf
24: var documento:String = util.getDoc(); 24: var document: String = util.getDoc ();
25: // devolve backend.html 25: / / returns backend.html
Isto não é nada mais que um simples package que simplifica as coisas em aplicações medias/grandes e que em muitas variadas situações se torna muito util. This is nothing more than a package that simplifies things in applications mean / large and in many different situations becomes very useful.
Podem fazer o download aqui . They can download here.
fiz um package pelo simples motivo de ajudar a quem ler a perceber como um package funciona, bem como se podem tornar simples a utilização destes packages principalmente pela sua reutilização por outros programadores e outras aplicações. I made a package for the simple reason to help people understand how to read a package works, and may become simpler to use these packages mainly for its reuse by other programmers and other applications. Podem ver o código comentado também. They can see the code also reviewed.
Aguarda-se feedback. Looks forward to feedback.
Este artigo está disponivel em pdf para download. This article is available in pdf format for download.
A Commentary
As always a real Public Utility Service, my dear!
Thanks for the tip!
Ved