Have you ever got error like in title? I was wondering what's the problem. I've checked everything twice. Spent on this some time. Solution? Check version of flash player and SDK that you're using. I had Flash player 10.1, I was compiling to 9.0 but was using SDK 4.2
Thursday, April 28, 2011
Sunday, April 17, 2011
link to page in new tab/window
Everybody hates popups and annoying ads. They usually cover site and try to open new site. So there are ad blockers, etc. But sometimes there's need for creating "polite" site that really needs to open new one.
I found this solution somewhere. Please use it for non-offensive cases.
To open new site (e.g. click n button in flash) we have to call javascript on site so it will create form and submit it on the fly.
ExternalInterface.call('( function (){var f = document.createElement("form") ;document.body.appendChild(f); f.style.display="none";f. setAttribute("target","_blank" );f.setAttribute("method"," POST");f.setAttribute("action" ,"'+url+'");f.submit(); })()');
IMPORTANT!
The whole code from above must be in one line.
There's url variable inside. Put there your url that is need to be open.
I found this solution somewhere. Please use it for non-offensive cases.
To open new site (e.g. click n button in flash) we have to call javascript on site so it will create form and submit it on the fly.
ExternalInterface.call('(
IMPORTANT!
The whole code from above must be in one line.
There's url variable inside. Put there your url that is need to be open.
Thursday, April 7, 2011
Cast vs as operator
I was wondering what's the difference between different types of casting. So I made some tests
var test1:Number;
trace( test1 as String); trace( test1.toString()); trace( String(test1));
//Output:
//null
//NaN
//NaN
OK, so we have two types casting. While 'as' returns us not defined String type (casted value also was not defined), standard casting creates instance that tries to use data casted type
var test1:Number;
trace( test1 as String); trace( test1.toString()); trace( String(test1));
//Output:
//null
//NaN
//NaN
OK, so we have two types casting. While 'as' returns us not defined String type (casted value also was not defined), standard casting creates instance that tries to use data casted type
Let's try the opposite way. But this time on defined instance
var test2:String = '100';
trace( test2 as Number);
trace( Number(test2));
var test2:String = '100';
trace( test2 as Number);
trace( Number(test2));
//Output:
//null
//100
Casting give us instance with data gathered from base class. But 'as' operator one more time returns null. I wondered how does it work. And I found. Check this example:
//null
//100
Casting give us instance with data gathered from base class. But 'as' operator one more time returns null. I wondered how does it work. And I found. Check this example:
var test3:Sprite = new Sprite();
trace( test3 as DisplayObject);
trace( test3 as MovieClip);
trace( test3 as DisplayObject);
trace( test3 as MovieClip);
Operator 'as' is concatenation of checking type of data and casting data. It casts only when base type is descendant of casted type. If expression is inherits casted class then it's returned. Otherwise it returns null
Etykiety:
actionscript,
as,
as operator,
as3,
cast,
casting,
displayobject,
movieclip,
nan,
null,
number,
sprite,
string
Sunday, April 3, 2011
From String to Boolean - casting problem
This is not a great discover, but sometimes it can help to save some time while wondering why there is true when should be false. I usually meet this situation while reading data from url GET parameters or from XML.
Let's check the example:
var stringTrue:String = 'true';
var stringFalse:String = 'false';
var boolDataTrue = new Boolean(stringTrue);
trace('#1 String true is casted to:', boolDataTrue);
//#1 String true is casted to: true
var boolDataFalse = new Boolean(stringFalse);
trace('#1 String false is casted to:', boolDataFalse);
//#1 String false is casted to: true
For this example I made two variables. In Boolean constructor ther's object as argument. But no matter what kind of string you put there it always deals it as 'true' expression
For quick and short fix you have to put there expresion that checks text and returns true or false as a proper type:
var boolDataTrue = new Boolean(stringTrue == 'true'?true:false);
trace('#2 String true is casted to:', boolDataTrue);
//#2 String true is casted to: true
var boolDataTrue = new Boolean(stringFalse == 'true'?true:false);
trace('#2 String true is casted to:', boolDataTrue);
//#2 String true is casted to: false
Let's check the example:
var stringTrue:String = 'true';
var stringFalse:String = 'false';
var boolDataTrue = new Boolean(stringTrue);
trace('#1 String true is casted to:', boolDataTrue);
//#1 String true is casted to: true
var boolDataFalse = new Boolean(stringFalse);
trace('#1 String false is casted to:', boolDataFalse);
//#1 String false is casted to: true
For this example I made two variables. In Boolean constructor ther's object as argument. But no matter what kind of string you put there it always deals it as 'true' expression
For quick and short fix you have to put there expresion that checks text and returns true or false as a proper type:
var boolDataTrue = new Boolean(stringTrue == 'true'?true:false);
trace('#2 String true is casted to:', boolDataTrue);
//#2 String true is casted to: true
var boolDataTrue = new Boolean(stringFalse == 'true'?true:false);
trace('#2 String true is casted to:', boolDataTrue);
//#2 String true is casted to: false
Subscribe to:
Posts (Atom)