Class URLLoader allow to load resources online and verify it state to take another actions.
An use example could be to check a server to show an alert when it was down:
Click with the right button to obtain source code.
Downloads
Projects
Utilities
Friends
LinksClass URLLoader allow to load resources online and verify it state to take another actions.
An use example could be to check a server to show an alert when it was down:
Click with the right button to obtain source code.
Flex applications with file upload through HTTPS has a security violation problem accepted by Internet community and it has no easy solution.
Although there are workaround proposed by the flex community, it not ever work and finally it’s better to use Flex and HTML mixed solutions.
Then is interesting to use javascript libraries as Dojo and ExternalInterface class which Flex use to communicate with the browser.
Following there is a simple example:
Click with the right button to obtain source code.
Functionality doesn´t solve managing files because is a very common HTML implementation.
We can use javascript to easily obtain (not infallible) browser language with Navigator object:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function checkLocation():void {
var location:String=ExternalInterface.call(
"function () {" +
" if (window.navigator.appName.indexOf('Explorer')!=-1) {" +
" return window.navigator.userLanguage;" +
" } else {" +
" return window.navigator.language;" +
" }" +
"}"
);
if (location=='') {
location="es-ES";
}
Alert.show(location);
}
]]>
</mx:Script>
<mx:Button click="checkLocation()" label="Check Location"/>
</mx:Application>
Example to convert Date to String and String to Date using Dojo 1.1.
String format must match with dojo ‘locale’. That can be achieve automatically or using dojo.locale=’es-es’.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>String to Date</title>
<script type="text/javascript"
src="http://o.aolcdn.com/dojo/1.0.0/dojo/dojo.xd.js"
djConfig="parseOnLoad: true, isDebug:true"></script>
<script type="text/javascript">
dojo.require("dojo.i18n");
dojo.require("dojo.date.locale");
dojo.require("dojo.parser");
function init() {
// Date to String
var d1=new Date();
var DtoS = dojo.date.locale.format(d1, {
datePattern:"dd 'de' MMMM 'de' yyyy HH:mm:ss",
selector:"date",
locale:'es-es'});
console.debug('Date to String: '+DtoS);
dojo.byId('d1').innerHTML=DtoS;
// String to Date
var StoD = dojo.date.locale.parse(DtoS,{
selector: 'date',
datePattern:"dd 'de' MMMM 'de' yyyy HH:mm:ss"
})
console.debug('String to Date: '+StoD.toString());
dojo.byId('d2').innerHTML=StoD.toString();
}
dojo.addOnLoad(init);
</script>
</head>
<body>
<div>Date to String: </div>
<div>String to Date: </div>
</body>
</html>
Parse a date like 06/26/2008 (with format MM/dd/yyyy) with locale=’es-es’ will produce an error.
Javascript function to validate NIF:
function validateNIF(nif) {
var val=false;
if(isNaN(nif)
&& nif.length>=8
&& isNaN(nif.charAt(nif.length-1))
&& !isNaN(nif.substr(0,nif.length-1))) {
var lockup = 'TRWAGMYFPDXBNJZSQVHLCKE';
var num=nif.substr(0,nif.length-1);
var let=nif.charAt(nif.length-1);
if(lockup.charAt(num % 23)==let) {
val=true
}
}
return val;
}
for the icon set used in this blog.