Type Casting And Equality
TypeError: Error #1034: Type Coercion failed: cannot convert uk.co.andrewrea.brickwall::BrickWall@24b1191 to uk.co.andrewrea.brickwall.BrickWall.
Does anyone know why this would be. I create a variable of Type BrickWall and then assign it a variable of type BrickWall the event data of the loader i.e.
ActionScript Code: wall = e.target.content.wall;
both wall and e.target.content.wall are of the same type of the same package, but seem to be handled as different types. Anyone know why this is?
Thanks,
Andrew
ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 10-09-2008, 03:45 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Type Casting
I have an input box where I want to put a number value that begins with zero. "016" I then put this value into an array and it drops the zero. I want the number value to be treated like a string. I have tried using the myText.toString() function, and the String(myText) constructor, but it still takes off the zero at the begining. does anyone have any ideas, or has anyone experienced this before?
Type Casting
Is there any way to convert String to Number? Flash doesn't convert it automaticly in my code. I used .valueOf but I didn't work.
Type Casting Problem
Hello gurus,
I have a problem:
while loading a number from a variable in a text file, into a script, i found that the number is not really a number but a string or a character. But i need it as a number to perform some operation. Can you please help me on how to convert that??
Type Casting To A Class Name
I'm trying to type cast an item in an array (inventoryList) to a Class, so I can addChild the movieClip to the stage. The items in the inventory 'carrotIcon and passportIcon' - I also have movieClips of the same name in the library with their own classes.
It works when I just change the line to 'addIconName = new carrotIcon()' for example. Maybe the answer is that I should use something else than 'Class' as the type cast. I've tried MovieClip to no avail.
var itemName:*;
var inventoryList:Array = new Array();
inventoryList.push("carrotIcon");
inventoryList.push("passportIcon");
for (var i:int = 0; i < (inventoryList.length); i++)
{
itemName = Class(inventoryList[i]); //this is the line I'm having problems.
addIconName = new itemName();
addChild(addIconName);
}
Thanks for looking!
Joe
Type Casting Problems
Quick Rundown of What I am doing so you can understand the logic is:
Building multipage Form In first Frame I hove no movies just initialized a bunch of Variables to store Data filled in from Forms on various Pages (frames 2 thru 7)
Page/Frame 2 is First Page which asks for Basic Details like Name Phone #s etc
I have a function that checks (when next page button is clicked) that checks Page form inputs are all filled correctly and if so updates the Variables (from frame 1) with the entered Data. Then on Return to the Page I prefill fields from the stored Variables.
Now the Problem:
For 4 different Phone numbers on the Page I have 3 inputs each (AreaCode, Prefix, Suffix)
When I go to store the entered values to 1 Variable each (Frame one/ Variable of type int/ to store the 10 digit number before sending to php serverside script) I concat the 3 input fields for each number and cast to int then on reenter page to preload the values again I cast the 10 digit int back to string and do a substr to divide them up and put them in the inputs as text.
However weird things happen Company Phone and Personal phone seem to usually work fine but Cell Phone and Fax get all muffed up the first time I renter (after leaving and returning they stay the same as first muffed up appearance)
Here is the portions relating to the Events please advise if you have any ideas how I can stop this behaviour. Thanks
Setting the Variable before leaving page
PHP Code:
cphone = int(CompanyPhoneAC.text + CompanyPhonePF.text + CompanyPhoneSF.text);
cfax= int(CompanyFaxAC.text + CompanyFaxPF.text + CompanyFaxSF.text);
pphone = int(PersPhoneAC.text + PersPhonePF.text + PersPhoneSF.text);
pcell = int(PersCellAC.text + PersCellPF.text + PersCellSF.text);
Setting the Inputs when Returning to Page
PHP Code:
var PersCAC:String = String(pcell);
PersCAC = PersCAC.substr(0,3);
if(PersCAC.length<3){
PersCAC = "" ;}
PersCellAC.text = PersCAC;
var PersCPF:String = String(pcell);
PersCPF = PersCPF.substr(3,3);
if(PersCPF.length<3){
PersCPF = "";}
PersCellPF.text = PersCPF;
var PersCSF:String = String(pcell);
PersCSF = PersCSF.substr(6,4);
if(PersCSF.length<4){
PersCSF = "";}
PersCellSF.text = PersCSF;
var PersPAC:String = String(pphone);
PersPAC = PersPAC.substr(0,3);
if(PersPAC.length<3){
PersPAC = "";}
PersPhoneAC.text = PersPAC;
var PersPPF:String = String(pphone);
PersPPF = PersPPF.substr(3,3);
if(PersPPF.length<3){
PersPPF = "";}
PersPhonePF.text = PersPPF;
var PersPSF:String = String(pphone);
PersPSF = PersPSF.substr(6,4);
if(PersPSF.length<4){
PersPSF = "";}
PersPhoneSF.text = PersPSF;
var CompanyPAC:String = String(cphone);
CompanyPAC = CompanyPAC.substr(0,3);
if(CompanyPAC.length<3){
CompanyPAC = "";}
CompanyPhoneAC.text = CompanyPAC;
var CompanyPPF:String = String(cphone);
CompanyPPF = CompanyPPF.substr(3,3);
if(CompanyPPF.length<3){
CompanyPPF = "";}
CompanyPhonePF.text = CompanyPPF;
var CompanyPSF:String = String(cphone);
CompanyPSF = CompanyPSF.substr(6,4);
if(CompanyPSF.length<4){
CompanyPSF = "";}
CompanyPhoneSF.text = CompanyPSF;
var CompanyFAC:String = String(cfax);
CompanyFAC = CompanyFAC.substr(0,3);
if(CompanyFAC.length<3){
CompanyFAC = "";}
CompanyFaxAC.text = CompanyFAC;
var CompanyFPF:String = String(cfax);
CompanyFPF = CompanyFPF.substr(3,3);
if(CompanyFPF.length<3){
CompanyFPF = "";}
CompanyFaxPF.text = CompanyFPF;
var CompanyFSF:String = String(cfax);
CompanyFSF = CompanyFSF.substr(6,4);
if(CompanyFSF.length<4){
CompanyFSF = "";}
CompanyFaxSF.text = CompanyFSF;
Dynamic Type Casting - Is It Possible?
Is there a way to do something like the following...?
Code:
var myClass:String = "blah";
var inst = new[myClass]();
I've invented the above syntax--though I'd be delighted if it turned out to work! For clarity, I would hope for something like the above code to be synonymous with the following:
Code:
var inst:blah = new blah();
...So is it possible to dynamically specify a class name when creating a new instance?
Type Casting Classes
Alright let's say I have a MovieClip in the library with the linkage set to TestClass and I have this code...
var string1:String = "Test";
var string2:String = "Class";
var testClass:* = new Class([string1 + string2])();
this.addChild(testClass);
so testClass should be an instance of TestClass, this works for me sometimes and sometimes it doesn't.
Does any one have any advice as a better way to do this, and what this tecnique is called ( root["string" + "1"])?
Thanks for all you guy's help!
How Strong Is Type Casting
I have a variable saved in the first frame of my fla file
var question:Number = 0;
I want to make it possible for sombody to jump around in the exersice so I built kind of a jumper and saved it in its own mc. In the mc I have a button called jump with the following code.
_root.question = q.text;
Now that question will work but when I tried to add one to my question variable it did something weird. Say I want to jump to question 2. When it tries to add one to my question variable I get 21. It seems that by saving q.text to my question variable, it gets recasted to a String. Has anybody else bumped into this problem.
Side note: I did fix this with parseInt. I am just curious why this happened in the first place, is type casting really not that strong?
Dynamic Type Casting - Is It Possible?
Is there a way to dynamically typecast a new instance? Maybe something like the following...?
Code:
var myClass:String = "blah";
var inst = new[myClass]();
I've invented the above syntax--though I'd be delighted if it turned out to work! For clarity, I would hope for something like the above code to be synonymous with the following:
Code:
var inst:blah = new blah();
...So is it possible to dynamically specify a class name when creating a new instance?
AS2 - Casting An Object To A Different Type
Hi all,
I'm trying to convert a String to Slide (mx.screens.Slide). Everytime I'm getting null.
ActionScript Code:
var slide = "slide_11"
_root.presentation.gotoSlide(slide);
I need to do this but it doesn't work. I have a string because slide_11 was in a xml file.
Any idea?
Help: Casting String Gotten From Xml To A Number Type
Hi all,
I have a major problem, I have parsed the data from an xml doc to global vars in flash and need to use a few of them as numbers for things the position of "nodes" on the screen. However I can not cast the data stored as a var to a number or int value.
For example in the code below when the set Node button is pressed it traces the "Node's" current X value, then the value in the global var gotten from the xml, which contains the x position of where to place the Node.
Next it creates a new var of Number Type and assigns it the Number value of the string in global var.
It then traces the new value of SNtopLeftX and sets the x pos of the Node's movie clip to the value of SNtopLeftX
However the Node doesn't move and this is the output I get from the traces
Start Node is at x = -734.5
nod_topLeftX is 16
TopLeftX = 16
SN TopLeftX = NaN
I do not understand why I am getting NaN when the string of nod_topLefX is 16, any ides?
-------------------------------------------------------------------------------------------------------------------
Attach Code
butNodeSet.onRelease = function() {
trace ("Start Node is at x = " + mcStartNode._x);
trace ("nod_topLeftX is " + nod_topLeftX);
var SNtopLeftX:Number = Number(nod_TopLeftX);
trace ("StartNode TopLeftX = " + SNtopLeftX);
mcStartNode._x = SNtopLeftX;
}
Help: Casting String Gotten From Xml To A Number Type
Hi all,
I have a major problem, I have parsed the data from an xml doc to global vars in flash and need to use a few of them as numbers for things the position of "nodes" on the screen. However I can not cast the data stored as a var to a number or int value.
For example in the code below when the set Node button is pressed it traces the "Node's" current X value, then the value in the global var gotten from the xml, which contains the x position of where to place the Node.
Next it creates a new var of Number Type and assigns it the Number value of the string in global var.
It then traces the new value of SNtopLeftX and sets the x pos of the Node's movie clip to the value of SNtopLeftX
However the Node doesn't move and this is the output I get from the traces
Start Node is at x = -734.5
nod_topLeftX is 16
TopLeftX = 16
SN TopLeftX = NaN
I do not understand why I am getting NaN when the string of nod_topLefX is 16, any ideas?
------------------------------------------------------------------------------------------------------------------- This is my Code
butNodeSet.onRelease = function() {
trace ("Start Node is at x = " + mcStartNode._x);
trace ("nod_topLeftX is " + nod_topLeftX);
var SNtopLeftX:Number = Number(nod_TopLeftX);
trace ("StartNode TopLeftX = " + SNtopLeftX);
mcStartNode._x = SNtopLeftX;
}
Instantiation/Type Casting Problem With GetChildAt
Alrighty so I'm kinda new with actionscript 3.0 and have been having a problem with getChildAt. I'm working on creating a dynamic menu have have found that when I addChildAt using a for loop it adds all the childs properly however when I go to use getChildAt on the MovieClip that I have created using "var newMC:MovieClip = mc_container.getChildAt(x)" it returns a problem saying "Implicit coercion of a value with static type flash.display:DisplayObject to a possible unrelated type flash.display:MovieClip"
Anyways I'm trying to get it to work however I found a work around that I'm not sure why works where I just do "var newMC = mc_container.getChildAt(x)" and that will let me access all of the variables and stuff however when I do a trace on the newMC it says type undefined... Anyways some help would be awsome, and heres my code btw, should be pretty easy to read.
import flash.display.MovieClip;
import flash.display.Shape;
var news_content_num = 1;
var news_padding = 0;
var news_padding_distance = 10;
var news_ymin = 0;
var news_full_width = 289;
var news_full_height = 154;
var news_compact_height = 61;
var news_shading_xval = 290;
var news_shading_yval = 255;
var news_bordersize = 1;
var news_shading_offset = 1;
var news_content:MovieClip = new MovieClip();
function drawBorder():Shape {
var border:Shape = new Shape();
border.name = "border_"+[x];
//Add the Left Line and then Top Line
border.graphics.lineStyle(news_bordersize, 0xCCCCCC, 1);
border.graphics.moveTo(0, news_ymin + news_full_height);
border.graphics.lineTo(0, news_ymin);
border.graphics.lineTo(news_full_width, news_ymin);
//Add the Right Side Drop Shadow
border.graphics.lineStyle(news_bordersize, 0X999999);
border.graphics.moveTo(news_full_width+1, news_ymin+2);
border.graphics.lineTo(news_full_width+1, news_full_height+news_shading_offset);
//Add the Bottom Side Drop Shadow
border.graphics.lineTo(2, news_full_height+news_shading_offset);
//this.addChild(border);
//Add the Right Side Border
border.graphics.lineStyle(news_bordersize, 0X000000);
border.graphics.moveTo(news_full_width,news_ymin);
border.graphics.lineTo(news_full_width, news_full_height);
//this.addChild(border);
//Add The Bottom Side Border
border.graphics.lineTo(0, news_full_height);
return border;
}
function drawNews_fullSize(x:Number) {
var mc = new MovieClip();
mc.name = "news_"+[x];
mc.y = news_padding;
mc.addChild(drawBorder());
news_content.addChildAt(mc, x);
}
function set_padding()
{
news_padding = news_padding + news_full_height + news_padding_distance;
}
for(x = 0; x < 4; x++){
drawNews_fullSize(x);
set_padding();
}
this.addChild(news_content);
//What I want it to run as...
//var news:MovieClip = news_content.getChildAt(0);
//What currently works...
//var news = news_content.getChildAt(0);
Fancy Box Type Moving Graphic Type Cool Efect But Im To Dumb Type Thingy
i am tring to make a box thinky simaler to the one on www.starvingeyes.com but cant even work out how to start it. is there anyone who can point me in the right direction or to a tutorial ?
the box has a graphic inside a grided box the sections of the graphic fade in and out as the mouse goes over them and displays random sections when the user is not moving the mouse over the box
i did find java tutorials for this effect but would much preffer it to come from flash as java is a bugger to get working on some machines
Any way thanks in advance for any help
Steven Green one_mad_punk@yahoo.co.uk
[F8] Equality Btn's & Mc's
Hi, I have a little problem... this menu that I'm working on, there are 8 btn's and a mc (rollOver & rollOut) that coincides with each button. Problem is trying to get the right mc to play with the right btn.
PHP Code:
for (i=1; i<9; i++) {
if(k == i) {
this["btn"+i].onRollOver = function() {
for (k=1; k<9; k++) {
_root["mc"+k].gotoAndPlay("over");
}
}
this["btn"+i].onRollOut = function() {
for (k=1; k<9; k++) {
_root["mc"+k].gotoAndPlay("out");
}
}
}
}
I know it's going to be an easy fix, any ideas? Thanks.
Equality Operator
Hi folks,
How can i check if 3 variables hold the same value in an if statement
var stepval1 = 20;
var stepval2 = 20;
var stepval3 = 20;
if (stepval1 == stepval2 == stepval3){
trace("inside 1 = 2 = 3");
}
Thanks
Problem With Equality Testing
I am having trouble with equality testing. Below is the code I have. I am not gettin the desired effect. Everything goes to the final scene ("no_win")
on (release) {
if (spin1num == spin2num == spin3num) {
gotoAndPlay("grand_prize", 1);
} else if (spin1col == spin2col == spin3col) {
gotoAndPlay("second_prize", 1);
} else if (spin1shape == spin2shape == spin3shape) {
gotoAndPlay("third_prize", 1);
} else{
gotoAndPlay("no_win", 1);
}
}
Actionscript, And Equality Comparisons
I have written a piece of code that opens and parses XML out of an XML file. I know you're saying "Hey, this post belongs elsewhere..." but please bear with me.
In my function I open and parse the XML completely fine. I have another function where I send the division of a piece of the file and the name of the Node, along with the dynamic text box to fill.
I am looking for a specific node name in that division, and so I am running a == comparison. I have traces all through the code so I can see what's going on. When the proper node name is found, I should dump in to another piece of code, but I don't.
The code is as follows. Any Ideas? If you can get me past this I will be extremely happy.
/////////////////////////////////////////////////
// Parse and populate dynamic boxes
function parseData(DataElementToSearch, ElementToFind, TextBoxName) {
trace("inside Parse data");
if (DataElementToSearch, nodeType == 3) {
trace("In the Attributes sections!!!!!!!!!!!!!!!!!!");
// The only time the textbox name is used.
this[TextBoxName] = dataPart.attributes[attr];
} else if (DataElementToSearch.nodetype == 1) {
// recursively loop through child nodes.
for (var i = 0; i trace("Node Name :"+DataElementToSearch.childnodes[i].nodeName+" Looking For: "+ElementToFind+" Count :"+i);
if (DataElementToSearch.childNodes[1].nodeName == ElementToFind) {
this[TextBoxName] = DataElementToSearch.childNodes[1].firstChild.nodeValue;
}
// If the name does not match, parse again!
parseData(DataElementToSearch.childnodes[i], ElementToFind, TextBoxName);
}
}
}
Input Text And Equality
Can someone please explain why this isn't working. I would like the user to enter the letter a, in an input box with the instance name boxa. When they press a button, I would like _root.great to go to the second frame. The code below is within the button that they will press to check their answer.
on (release) {
if (boxa==a) {
tellTarget ("_root.great") {
gotoAndStop(2);
}
}
}
Thanks
Equality... Multiple Values?
I'm working on an input form that checks whether the user has entered correct data and gives them feedback as to what they typed in right/wrong. What is the syntax for allowing multiple values to be correct?
In this case, the correct address value is "123 Main St", but I also want them to be able to put in "123 Main St." or "123 main st" or "123 MAIN ST", etc.
on(release) {
if (address == "123 Main St"){
textbox = "
Address is CORRECT.";
} else {
textbox = "
Address is INCORRECT.";
}
}
I tried using the deprecated "or", separating the values with commas, etc. but haven't found anything that worked.
[F8] Equality In Dynamic TextFields
Hey all, I'm trying to equate (==) two dynamic textfields and having some difficulty.
CODE:
for(i=0; i<37; i++) {
if(this["o"+i] == this.cal_mc.lrgNum) {
this["o"+i].textColor = 0xBAFF0A;
} else {
this["o"+i].textColor = 0xFFFFFF;
}
}
Am I even close?
ApplicationDomain.currentDomain Equality
Hi all,
I'm having a problem comparing an ApplicationDomain to another. Here's a very simple example:
var test1:ApplicationDomain = ApplicationDomain.currentDomain;
trace(String(test1 === ApplicationDomain.currentDomain));
This returns false. So does ==. ObjectUtil.compare returns true, however it also returns true when comparing different applicationDomains pointing at the same root.
Any help would be greatly appreciated! Thanks,
Josh
Pulling My Hair Out : Equality Or Equals?
Hey all,
Megatoon and I are working on this game that requires the user to type in their answer into a text box with field name "answer". The text box is then compared to the actual answer which is a variable "Q". So I have the following:
if (answer == Q){
_root.movie.gotoAndPlay(2);
} else {
_root.movie.gotoAndPlay(10);
}
Now check this...it only works some of the time!? I don't know what I'm doing wrong. I've even tried:
if (answer = Q)
but this always sends my movie to the else directive.
Any ideas?
Thanks.
Using Imported XML Nodes To Test Equality
I am loading a remote XML document in a new XML object and I am accessing a node that contains a time, for example:
<sunr>6:57 AM</sunr>
What I am attempting to do is use the hour, in this case "6," along with .getUTChour to create an inequality in an if statement that results in a frame change in another movie clip.
I think I understand how to change frames in a separate movie clip, but I am struggling with the task of pulling out the 6 from the node. I originally wanted to use the entire time, but I decided that that would be too complicated.
So far I have experimented by storing the node in a variable and then using .length and for loops to try and redefine the node but this only results in things being undefined. I'm out of ideas at this point, any help would be great.
Testing Two Multidimensional Arrays For Equality
does anyone know a better way of testing multidimensional arrays for equality. The one way I know of is to loop through elements in both testing each element for eqaulity. are there any quicker ways?
cheers
Nathan
FilterFunc Item Equality Error
Does anyone know why this works:
private function filterListener(evt:Object):Void {
dsFiles.filterFunc = function(item:Object):Boolean {
return (item.name == "TestClientB");
}
}
But this does not: ?????
private function filterListener(evt:Object):Void {
clientListSel = "TestClientB";
dsFiles.filterFunc = function(item:Object):Boolean {
return (item.name == clientListSel);
}
}
Edited: 12/09/2006 at 03:06:36 PM by cayennecode
String Variable Equality Comparison Not Working
Hey I never have pulled the urgent card before, so I hope someone will be generous enough to help me out on this FUNDAMENTAL...grrrr.
I am having trouble with a string equality comparison. Flash is ignoring it.
I am trying to compare an array value to a string in an if():
Code:
if (myArray[x].title !== undefined){
if (myArray[x].title !== "Patents") {
trace(myArray[x].title);
}
//if undefined or "Patents" then do nothing
};
I totally am lost. The !== undefined part works great. Anytime there IS a value for a title it does what I want. But when I try to create an expection or rule around the string of the title Flash ignors what I am doing. I copied the string straight from the array, so the text is a perfect match.
I've also tried dumping the array value into a variable, but it ignors that too. It seems I dont understand comparing strings. But my moock says things like:
"Flash" == "Flash"
so what gives?
Comaparison Operators: Testing Equality Of Multiple Variables
hello all.
i was wondering if there is a short hand way of testing that multiple variables have the same value... regardless of what that value may be. in the simplest terms i want to test
If VarA = VarB = VarC then do something.
What I am currently doing is:
if ((VarA == VarB) and (VarB == VarC)){
then do something;
}
My way works... but it is not practical if you have a bunch of vars.
Is there a way to do this without getting into a loop?
thanks
meglomor
AS3: Casting
What is the difference between the following two statements?
ActionScript Code:
oBj1 = XML(oBj2);
and
ActionScript Code:
oBj1 = oBj2 as XML;
TIA, Eugene
Casting
Hi. Why does the attached lines return true, all three of them?
I understand the first returning true, I could even understand the second (strictly from the documentation it's ok to return true, but I think the "as" word is misleading), but I definitely don't understand why the third one is true.
Could some one explain me the exact semantics of those thing?
Thanks,
FaQ
Attach Code
var a:Sprite = new Sprite();
trace(a is Sprite, " = a is Sprite");
trace((a as DisplayObject) is Sprite, " = (a as DisplayObject) is Sprite");
trace(DisplayObject(a) is Sprite, " = DisplayObject(a) is Sprite");
Web Casting And Forums?
Hi folks, I need a pointer in the right direction here!
I have to setup a live webcam and a stills webcam on 10min refresh, aslo I need to make a forum page all in flash mx2004, can anyone point me in the direction of some good tutorials that I can just dive into?
Any help greatly appriciated.
Cheers.
Casting To Integer - What's Going On?
Look at this piece of code:
---------------------
alint = "0060";
trace (int(alint));
---------------------
this gives the value 48.
-48!?!? Where does that come from?
Help appreciated!
Casting An Array To An Int
I have this trace statement that reads out a array of an sql database-
trace(re.result._items[row][name]);
It prints this
2
8 *
3
1
5 *
2
0
5 *
1
I am trying to pull out the numbers with a * and make them seperate int's. Whats the best way to do this? Thanks in advance!
Casting To Integer?
Hi,
I am new to actionscript .
How do I cut off the decimal part of a Number to get only an integer.
I want to display % complete of an upload, and I want for example
75.43% to read 75%
So there is no integer type in ActionScript 2? only Number?
Is there some way to cast the darn thing ?
Or how do i do it?
-thanks
Instanceof And Casting; Anyone?
I'm setting up a nice event-handling class for taking care of the WebServiceConnector. I'm trying to do a clean cast of the result object, so I can get it back into type safety before handing it off to whatever class asked for it.
This (and variations thereof) is what I've been trying for a while now:
Code:
private function resultListener(res:Object)
{
if(res.target.results instanceof Boolean)
{
var return:Boolean = Boolean(res.target.results);
}
else if(res.target.results instanceof String)
{
var return:String = String(res.target.results);
}
else if(res.target.results instanceof Number)
{
var return:Number = Number(res.target.results);
}
else if(res.target.results instanceof Array)
{
var return:Array = Array(res.target.results);
}
else if(res.target.results instanceof Object) //(should) always true
{
var return:Object = Object(res.target.results);
}
}
None of these if-clauses are ever true. I would suspect - at the very least - that "instanceof Object" would be a catch-all, but it isn't. So... what type is results?
Do you have any idea as to how I can create this function - casting the result to a known AS-type?
Casting To Boolean From XML
How would you get Flash to recognise a value passed via XML as a boolean true/false...
Ive tried casting it to force it to be Boolean, which I think ive done correctly as:
ActionScript Code:
var run:Boolean = Boolean(xmlData.run.text())
Ive also tried removing the .text() however it always goes true, anyone know what i'm doing wrong...?
XML Node And Casting To Int
Just came across a strange behaviour in my Flex app when casting a xml node value to int.
Code:
//The attibute is set to '2'
var selectedCodeId:int = int(selectedFilterTreeNode.@codeId); //gave 2
var selectedCodeId:int = selectedFilterTreeNode.@codeId as int; //gave 0
Anyone seen this before?
SharedObject Casting
I'm storing a custom class object in a local SharedObject file, and then later trying to retrieve it. When I try to retrieve it, I get the following error:"Type Coercion failed: cannot convert Object@10547d59 to AS3.accounting.UserAccount."
The "@10547d59" changes every time obviously since it is just a temporary type name.
The 'basic' code to save the object is this:
ActionScript Code:
public function createUser(name:String, password:String):Boolean{
var users:Object = userAccounts.data.users;
if(!users) users = new Object();
if(users[name]) return false;
user = new UserAccount(name, password);
users[name] = user;
userAccounts.setProperty("users", users);
userAccounts.flush();
return true;
}
The 'basic' code to load the object is this:
ActionScript Code:
public function findUser(name:String, password:String):Boolean{
var users = userAccounts.data.users;
if(!users || !users[name]) return false;
user = users[name];
return true;
}
The object being sent-to the file is of type UserAccount, and the data retrieved is attempting to be placed in a UserAccount object, but the retrieved data doesn't seem to remember what type it was, and since Object is higher in the inheritance hierarchy it won't naturally convert it for me.
If you have any ideas, please feel free to share them. Otherwise, when I figure out the best solution I'll post it below.
FLVMovie Casting
Hi there...
I'm new to the hole AS3 stuff... so sorry if the question is kind of silly.
For the Question:
I created my own FLVMovie Class:
Code:
package {
import flash.events.MouseEvent;
import fl.video.FLVPlayback;
public class FLVMovie extends FLVPlayback{
public function FLVMovie(){
this.addEventListener(MouseEvent.CLICK,clickHandler);
}
public function clickHandler(btn){
trace('movie click');
this.stop();
}
}
}
No for the question itself.... I have a existing FLVPlayback on the Stage... is there a way to convert / cast it into a FLVMovie so it has the Click event handler?
thx...
Casting MC To FLVPlayback
I need to create a FLVPlayback component dynamically, but it seems I can't cast the MovieClip returned by attachMovie to FLVPlayback class, it always return null. If I create a new document, it works well. I think this problem happen when I tell Flash to export classes at frame 2, but my component is being attached at frame 3. Is there a way to export classes for frame 2 and still being able to cast the Component?
Casting Error In CS 3
Hi guys,
I maintain an API for which have a huge chunk of its code loaded dynamically from the server. This is all fine and dandy until I try to parse costume class instances back and forward between the current file and the loaded remote API file.
Basically I get a cast error as below:
TypeError: Error #1034: Type Coercion failed: cannot convert Nonoba.api.net::Connection@408e47e1 to Nonoba.api.net.Connection.
My initial ida for a solution was to simply just accept :* and do
var conn:Connection = parsedObject as Connection
but this results in a null value
Any ideas?
Casting Woes
Imagine a quick scenario;
_thumbs is a Sprite, inside it is a custom class called "thumb1" (extends MovieClip) and inside that is a sprite called "nail". Nail is a libraryitem. Nail has a child called blocker (that's in the library item already).
Now, this works fine;
ActionScript Code:
var t = _thumbs.getChildByName("thumb"+i);var sx = t.getChildByName("nail");TweenMax.to(sx.blocker,1,{yada});
Wheras this works fine, I can't for my life figure out how to cast these variables. If I try making them DisplayObjects or Sprites or MovieClips or whatnot it all throws error with either implicit coercion or reference to a undefined method getChildByName
Grateful for any insight.
Casting Vs. Converting
hey, thought it might be useful to some to see these tests i ran:
ActionScript Code:
private function testTypeConversions () :void {
var i:int = 10;
trace("int as String:"+(i as String)); //null
trace("String(int):"+String(i)); //"10"
trace("int.toString():"+i.toString()); //"10"
var num:Number = 0.5;
trace("Number as String:"+(num as String)); //null
trace("String(Number):"+String(num)); //"0.5"
trace("Number.toString():"+num.toString()); //"0.5
var str:String = "2.3";
trace("String as int:"+(str as int)); //null
trace("int(String):"+int(str)); //2
trace("parseInt(String):"+parseInt(str)); //2
trace("String as Number:"+(str as Number)); //null
trace("Number(String):"+Number(str)); //2.3
}
the moral of the story here is that AS2-style casting:
ActionScript Code:
Type(value)
can actually convert primitives to a different datatype, while AS3-style casting:
ActionScript Code:
value as Type
will not convert (and will return null if the cast is invalid).
while it may be tempting, then, to just stick with AS2-style casting, i'm pretty sure it's preferable to use AS3-style casting and conversion functions like toString, parseInt, and parseFloat. that's more in keeping with other OO languages.
also, as a side note, the AS3 language reference actually refers to AS2 casting functions as conversion functions. that's what they do...don't (do what i did and) confuse them with casting via 'as'!
Implicit Coercion Of A Value Of Type String To An Unrelated Type Function
Hi there
Why I can't use an "eval" function (i am not sure this is the right terminology) inside addEventListener (I put in yellow) ?
for (i=1;i<10;i++) {
var constructFunction1:String;
var constructFunction2:String;
constructFunction1="choix3"+i+"Handler";
constructFunction2="choix3"+i+"HandlerClick";
MovieClip(this["choix"+i]).addEventListener(MouseEvent.MOUSE_OVER,constructFunction);
Then error in the compiler:
1067: Implicit coercion of a value of type String to an unrelated type Function.
Pixel/Bitmap Vs True Type/Open Type Fonts
I'm new to flash and I've been getting conflicting advice on which type of fonts to use. I've done several searches in the forms and I'm still just as puzzled so I've decided to start my own discussion on the subject. So here we go:
1) Are Pixel and bitmap fonts the same type of font?
2) Which is better to use True Type or Pixel (bitmap) fonts and where and/or why
Please help this newbie to flash and jump in with your opinion, experiences, etc.
Thanks
Casting A String To An Object
I'm having trouble passing an object parameter using a string concatenation in a for loop...
in the for loop, I duplicate movieClips, copying a movie called "glass" and try to register it's speeds with the register() function below.
for (i = 1; i <= numObjects; i++) {
duplicateMovieClip(glass,"glass" + i, i);
register("glass" + i,20,20,20);
}
function register(object, xspeed, yspeed, rspeed) {
objects.push(object);
object._xspeed = xspeed * (2 * Math.random() - 1);
object._yspeed = yspeed * (2 * Math.random() - 1);
object._rspeed = rspeed * (2 * Math.random() - 1);
}
unfortunately, when passing tmp as "glass" + i, register thinks its a string, not an object. The object appear on stage, but doesn't move. If I hard code register() passing in as register(glass2,20,20,20) it does move.
How do I cast the string I pass in as an object?
Casting (like In Java?) Or Help In This Thing
hi guys,
how do you cast, like you do in Java?
string = (String)(skaljeasjkle)
..
or, you can just help me to do this
you see, i have a class Q. i named my instances of these q0, q1, q2 to qn.
in this class Q, i have vars question, a0, a1, a2, a3.
i want flash to read the Q (q0, q1, q2, qn) depending on the counter at a moment in time. for example...
var temp = (Q)(q + "" + counter);
//so i can access the qn's vars..
trace(qcounter.a1);
i THINK you can do something like that in Java but even there i'm already rusty.
if i don't use this method, i'll have a HUGE if statement.. or switch. and of course, i wouldnt want to do that.
Casting A String Into A Function
Hi,
I would like to convert a String to a function:
Code:
public function Init(command:String)
{
//i need to call the handleHowTo() function from here base on the command String
}
public function handleHowTo()
{
trace("yes");
}
Init("handleHowTo");
How can I convert the command:String to a function to call the function handleHowTo() ? is there a way to cast a String into a Function ???
Thanks ;)
|