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?
ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 01-14-2008, 07:33 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
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?
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;
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!
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
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?
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);
Newbie Casting Question - Dynamic Video Calls
i tried to track this info down on my own, here and elsewhere, but it just demonstrates my ignorance of AS 3 syntax. greatly welcome any help you can provide me here, ASAP!
i am building an app that:
1.) takes an input text field where user enters a URI;
2.) via a button press, splits this into two (an earlier post has helped me get this far);
3.) takes the separate strings and populates .connect and .play names of an RTMP video stream
it's #3 that's the issue -- i have gotten as far as the string split. how to plug these values in dynamically?
the relevant code (i skipped other button control functionality to get to the meat of the matter):
Code:
//instantiate text fields + properties
inputTxt.text = "";
connectTxt.text = "";
playTxt.text = "";
inputTxt.background = true;
//video instance
var nc:NetConnection = new NetConnection();
var ns:NetStream;
nc.objectEncoding = flash.net.ObjectEncoding.AMF0;
nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
var counter:int = 0;
// mouse event handler
select_btn.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
//code skipped
function mouseDownHandler(event:MouseEvent):void {
var urlStr:String = inputTxt.text;
var arr = urlStr.split("/", 4);
var myPattern:RegExp = /,/g;
var newurlStr:String = arr;
var connecturlStr:String = newurlStr.replace(myPattern, "/");
connectTxt.text = connecturlStr;
var shift = connecturlStr.length;
var playStr = urlStr.slice(shift + 1);
playTxt.text = playStr;
}
this does the string split, and populates the fields. now:
Code:
function onNetStatus(evt:NetStatusEvent, event:MouseEvent, playStr:String, connecturlStr:String):void {
ns = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
//ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
var myVideo:Video = new Video(320,240);
myVideo.attachNetStream(ns);
myVideo.x = 140;
myVideo.y = 80;
addChild(myVideo);
ns.bufferTime = 5;
ns.play("playStr",true);
trace(evt.info.code);
//}
}
nc.connect("connecturlStr",true);
how to plug these strings into nc.connect and ns.play?
note that i have removed the nc.connect for the onNetStatus function, since if i hard code the URI info into ns.play and nc.connect, the video only comes up if nc.connect is outside of onNetStatus. and hard-coded, the video comes up like a charm, so it's not the stream -- tracing "evt" shows it's connected, but again only if values are hard-coded.
i understand some event has to populate these values, but trying to wed the button event to the .connect and .play values has not worked, either. casting for a solution! thanks for your help.
Problems With Casting Or String (literals?), And Dynamic References
Can someone please tell me the difference in these three code chunks?
1) is it casting a string, or incorrect syntax?
2) this works,
3) if #2 works as a plain "" string, then what cases would prompt the string to need String("whatever") ?
if menu_item_txt is a textField at _level0:
1)
Code:
for (var i = 0; i < 7; i++) {
var myText:Object = this[String(menu_item_txt) + i];
//trace(myText);
myText.autoSize = true;
myText.embedFonts = true;
myText.antiAliasType = "advanced";
myText.gridFitType = "subpixel";
myText.thickness = 0;
myText.sharpness = 45;
}
2)
Code:
for (var i = 0; i < 7; i++) {
var myText:Object = this["menu_item_txt" + i];
//trace(myText);
myText.autoSize = true;
myText.embedFonts = true;
myText.antiAliasType = "advanced";
myText.gridFitType = "subpixel";
myText.thickness = 0;
myText.sharpness = 45;
}
3)
Code:
for (var i = 0; i < 7; i++) {
var myText:Object = this[String("menu_item_txt") + i];
//trace(myText);
myText.autoSize = true;
myText.embedFonts = true;
myText.antiAliasType = "advanced";
myText.gridFitType = "subpixel";
myText.thickness = 0;
myText.sharpness = 45;
}
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
Type In A Dynamic Field
A small question.
I have a field where you can input your email address.
As I dont have much room I want the text -put your email ad here- in the box itself.
as soon as the person starts typing I want it to disapear.
Anyone know how?
Dynamic Type Problem
I have a dynamic text box call "color.txt" and two Movie clip buttons one called Red and one called Yellow.
When I press the button the name of the button is passed to the text box. When I press the second button the
name is not replaced. Do I have to create a seperate function to do this or is there an eaiser way?
Thanks,
_root.red.onPress = function(){
_root.colorTxt.text = "Red";
}
_root.yellow.onPress = function(){
_root.colorTxt.text = "Yellow";
}
Keep Font Type With Dynamic Texts
Hey guys,
I have designed a flash movie with dynamic texts which uses this line of coding to read from an external text file:
Code:
loadVariables("flashtexts/info.txt", textbox);
My problem is that I want to use a font that is not installed on other windows by default. when ever I look at my swf file, I see that the fonts have changed.
I should add that I do NOT have any problem with this font when I use static texts in my flash movie.
Please help me with this little problem.
Leading + Dynamic Type *sigh* You Can't Be Serious
So just thought I would ask since - well - none of the archives are telling me what I want to hear. It Looks like there is no way to compress the line space of dynamic text in AS1. Is this true? Negative leading is not supported in AS1. So what else to do? I'm not breaking up text by character string lengths etc. This seems completely rediculous for a dynamic graphics tool.
grrrr..
Anyone also know if the leading property was expanded in AS2?
thanks,
-AB
Creating Dynamic Outlined Type
anyone know how to do this.
It would seem that there should be a stroke capability on dynamic text but there isn't. Thickness will not work as its very limited in values you can enter.
Also using a bold set behind will not work with this type either.
I had this issue on another project and ended up using images as I didn't have time to fool around and find a solution. Anyway the issue is back again and I have some time to fool about with it. So I was wondering if anyone has tried to tackle this issue before and had some pointers or pitfalls when dealing with it.
thanks
StartDrag With Dynamic Ot Input Text Type... HOW?
I have been racking my brains over this now for quite some time, I did try this ages ago, and still could could accoplish it, so I gave up and used buttons to move the text boxes.
But now I really do want to use the StartDrag method.
As far as I understand, you can only make a movieclip draggable, so if I change dynamic or input text box to an MC, it is no longer editable, as the ON(press) command takes control.
So how can it be done?? I have done countless earches, and cannot find the answer.
There is a website which has the idea I require, except their "Draggable" text is not directly editable (which is what I would like)
The site link is http://www.tshirtcandy.com/ , if you click design, then select any old TShirt, it will take you to text bit I was talking about.
I am sure it is easy, and obviusly it can be done, as it has been done on the above website.
Thanks in advance
[F8] Strict Type And Dynamic Text Fields
Hi
I was wondering what the best way is of doing this:
Say I am using a dynamic text field to display a message. If I create the text field on my stage and give it an instance name in the properties panel should I declare that variable in the script as well? If I am trying to stick to the strickt data typing way of doing things?
I mean, say the instance name of my text field is message_txt, should I create an action on the frame -
var message_txt:String;
or is this overkill?
Type Settings With A Dynamic Text Field
I have some dynamically generated text (generated within the swf) that i'm sending to a dynamic text field (in the same swf). When I created it on the stage I set the color, the width between characters (AV), the text size, and the font...but when it's played in the browser or even in testing, none of those settings are applied to the text except for the color. Any ideas about what I'm doing wrong?
Thanks in advance!
[Q] Supported Video File Type For Dynamic Loading...
Howdy...
I 'think' I know the answer but I just want somebody confirm this...
Can somebody tell me if following paragraph is correct or not??? Thanks...
Quote:
If I want to load the video file dynamically, I can only use either FLV or SWF file...
Dynamic Text, Data Type, Variable Problem
I am trying to load one of 80 text fields into a dynamic text box. I have an Array that is filled with all 80 field labels in random order. My concept is that I should be able to pop the last field out of the array, set it equal to a variable, and use that variable in the statement defining the text of the text box. But it doesn't work. It returns undefined.
Example:
ActionScript Code:
nextQuestion = myList2.pop();myTextField_txt.text = externalData.nextQuestion;
The second line of the statement works if I hard code the text field name.
Example:
ActionScript Code:
myTextField_txt.text=externalData.question37;
But it does not work if I use a variable set to question37.
I think this may have to do with the data type of the variable. It is a string. Any ideas or suggestions?
Dynamic Text, Data Type, Variable Problem
I am trying to load one of 80 text fields into a dynamic text box. I have an Array that is filled with all 80 field labels in random order. My concept is that I should be able to pop the last field out of the array, set it equal to a variable, and use that variable in the statement defining the text of the text box. But it doesn't work. It returns undefined.
Example:
ActionScript Code:
nextQuestion = myList2.pop();myTextField_txt.text = externalData.nextQuestion;
The second line of the statement works if I hard code the text field name.
Example:
ActionScript Code:
myTextField_txt.text=externalData.question37;
But it does not work if I use a variable set to question37.
I think this may have to do with the data type of the variable. It is a string. Any ideas or suggestions?
AS2: Hard - Type Effect In A Dynamic Textfield In Whose Html = True
I only found on the boards how to make it on normal dynamic textfields. But I wanted to use it in dynamic textfields that renders text in html format.
I started 4 hours ago.. and I think I'm gonna stop first. It's a bit tiring and it looks like it's going to be very tough to do this using if else's.
I wanna know if any one here has attempted to do such a thing?
How I pictured the program to go through a given text, such as:
<P ALIGN="CENTER"> HELLO<MAN<What's your name </P>
First, it will write the tags on a new string:
<P ALIGN="CENTER"></P>
But, it will remember where the non-tag portion is (location 18 to 46), then what it does is sets the textfeild.htmlText to <P ALIGN="CENTER"></P>
Second, it will slowly write in the non-tags, probably through an interval.
a: <P ALIGN="CENTER"> </P>
b: <P ALIGN="CENTER"> H</P>
c: <P ALIGN="CENTER"> HE</P>
etc..
it should work, and it allows the person to use html tags.
But... hehe it's a lot of work for such a simple effect.
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 ;)
|