Actionscript 3 :: Casting One Type To Another?
Mar 12, 2012
I have a base class called Room and a subclass called Attic, and another called Basement.
I have a controller class that has an attribute called CurrentLocation which is type Room. The idea is I want to be able to put Attic or Basement in that property and get it back, then cast that to whatever type it is.
So if on the controller the content is of type Attic, I'm trying to figure out how to explicitly cast it. I thought I knew but its not working... Here's what I thought it would be, borrowing from Java:
var myAttic:Attic = (Attic) Controller.CurrentLocation;
This gives me a syntax error:
1086: Syntax error: expecting semicolon before instance.
So how do you cast implicitly? Or can you? I could swear I've done this before as as3.
View 1 Replies
Similar Posts:
Jul 5, 2010
I wrote a post a week ago but it seems no one is able to help or I didn't explain my problem well enough, so here I go again.I want to load an external SWF, get an object reference from it and add it to the PV3D scene of my main class. The problem is even though the types have the same names, they are not recognized as the same type.
---------------------------------pv3Dviewer--------------------------- -----------
package {
import org.papervision3d.objects.primitives.Sphere;
public class pv3Dviewer extends Sprite {
[code]....
When pv3Dviewer is run, it traces "no". If I try to assign shereRemote without type casting i get this error:TypeError: Error #1034: Type Coercion failed: cannot convert org.papervision3d.objects.primitives::Sphere@59930b1 to org.papervision3d.objects.primitives.Sphere.
View 7 Replies
May 1, 2007
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);
[code]....
View 2 Replies
Nov 13, 2009
I am trying to import a SWF file into a custom loader and then treat the loaded SWF file as a MovieClip object. The code for the functionality can be seen below.
public function loadMyMovie(movie:String)
{
var now:Date = new Date();
var rnd:String = "?randomize=" + now.time;
[Code].....
When I do this I get the following error.
"Implicit coercion of a value with static type flash.display:DisplayObject to a possibly unrelated type flash.display:MovieClip."
View 2 Replies
Apr 28, 2011
My application currently contains a number of Widgets that are managed by a Widget Manager. When the user clicks on a widget (e.g. a Helper widget), the Widget Manager loads the widget into a separate sibling application domain with the following line of code:
wgtInfo.load(null, null, null, moduleFactory); //wgtInfo = IModuleInfo
However, I am unable to use the widget's variables and functions later on. I attempt to find the Helper widget from the Widget Manager's list of widgets, and I do successfully. But when I try to caste the Helper Widget from type IBaseWidget (the interface all widgets share) to type HelperWidget, I receive the following error:
TypeError: Error #1034: Type Coercion failed.....
This is because the application domain of the class trying to use the Helper widget is different from the application domain of the Helper Widget. I tried to fix this by loading all widgets into the same application domain as the loader:
wgtInfo.load(ApplicationDomain.currentDomain, null, null, moduleFactory);
I now get the following error whenever I attempt to load the Helper widget:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
How can I load my Helper widget into a common application domain that is accessible by the other widgets?
View 3 Replies
Jul 15, 2009
This is the error I am getting in the handleModuleReady function:
[Fault] exception, information=TypeError: Error #1034: Type Coercion failed:
can not convert MyModule@39b8479 to IModuleInterface.
I have an application setup and I have created modules to load at runtime in order to decrease the filesize (as most users will only ever need one of the modules).
<!-- maker.mxml -->
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns="*"
[code].....
View 2 Replies
Jan 2, 2012
Is it possible to develop a Flex Mobile App to record the complete actions we do on the mobile?? Like recording (screencasting) all the activities I do on the Mobile Phone. I want to do this using Flash Builder 4.5.
View 2 Replies
Feb 5, 2009
haven't wrote here for a while!This is what I'm trying to do:
var level:Number = 1;
var goat:* = "thisIsLevel" + (level + 1);
var camel:Function = goat;
[code].....
View 3 Replies
Jan 7, 2010
I am calling on different types classes from within a loop. The objects can be of different types so therefore I am using the getDefinitionByName method. here is a piece of my code:
for(var y = 0; y < mapH; y++)
{
brickHolder[y] = new Array();
[Code]....
But I got an error when I tried to call on methods. The interface is blank; doesn't have any methods in it. I am not sure if that makes a difference. But the parent class inherits it and the subclasses inherit the parent class. Can I instead use the parent class?
var brick:ParentBrick2 = ParentBrick2(new classRef());
In a nutshell, what can I do to loosely cast these objects so I am able to use any subclass methods that get called?
View 4 Replies
Aug 16, 2011
I made a class in AS3 for representing complex numbers. It does not inherit anything. How can I enable casting from e.g. Numbers? I.e. I want this:
5 as Complex
to be the same as this:
new Complex(5);
is there a magic cast() function I can put in my class?
View 1 Replies
Aug 18, 2011
Any class common between flash swf file, loaded in swfloader turns our to throw error ypeError: Error #1034: Type Coercion failed: cannot convert edia::PlayerContentView@12babac1 to media.PlayerContentView.My main swf has same class, since its been used by appplication all over, but when swfloader creates object of same name class, it adds 12babac1 to class name. and doesn't work for simple access of array values
public function get Current():media.PlayerContentView
{
return contentItems[VZPlay.CurrentIndex] as PlayerContentView;
[code].....
View 1 Replies
Nov 4, 2010
What is exactly difference between casting with np: DisplayObject(myObj) or
myObj as DisplayObject
View 9 Replies
Jan 10, 2011
Okay so quite an ambiguous title but what I'm trying to do is cast a shadow off shapes from a light source. Simple enough and I have it working but I just can't work out how to fix the problem of when the light source is at a certain angle to the shape I'm casting a shadow from.I know it's the whole 180 to -180 thing, but I just can't think of a work around.I've attached the swf and fla so you can see for yourself.Basically the code works by chucking points of the shape in an array and then arranging the array by the angle of each point from the light source. No big deal. From there it just takes the first and last point in the array and draws a shadow from there. Sketchy for the time being I know, but I just don't understand why it's doing what it is.
View 0 Replies
May 1, 2007
Let's say I have 3 items in the same package:Shouter interface - requires implementers to implement the shout() functionShell class - implements Shouter...this Shell.swf is to be loaded remotely from:ShellLoader class - loads Shell from a remote server, casts it as a Shouter and invokes its shout() function...uses allowDomain in order to cross-domain script.Now let's say ShellLoader.swf lives on and Shell.swf lives on ....I've got a cross-domain policy on Using LoaderContext's ApplicationDomain and SecurityDomain, I'm able to load and cast the Shell object as a Shouter and invoke the shout() function. Everything ok here.
Now let's say ShellLoader is run locally and is localTrusted. Shell.swf still lives on I'm now unable to use SecurityDomain property of LoaderContext within ShellLoader because it is now run locally. Shell.swf now exists in a different ApplicationDomain as my ShellLoader and I get the error "Type Coercion failed" when I try to cast the loader content as a Shouter.Is there anyway to resolve this issue? I believe it will require Shell.swf to be loaded in the same ApplicationDomain as ShellLoader but I don't know any way to do this when ShellLoader is run locally. Perhaps this is prevented in the Flash player on purpose?
View 7 Replies
Sep 1, 2009
I'm new to flash and actionscripting (i come from the land of ansi c but have traveled extensively). I've created a great animated animated 3d movie clip and want to have them generated on the stage in relation to an xml file. I've gotten this to work with a 2d movie clip but am running into problems casting a 3d object.my object (a movie clip - boxContainer with an instance name of boxContainer_mc) is built out of all movie clips in the following way (shown in tree form):[code]
View 6 Replies
Jan 14, 2010
I've been reading about this issue on the forums today, but I still don't understand what i'm doing wrong here:var theMC:String = "mcMenuItem1";var myX=[theMC];trace("myX = "+myX);myX.gotoAndStop(2);From what I've read, this should cast theMC string into a movie clip that exists on the stage, but I still get the error:TypeError: Error #1006: gotoAndStop is not a function.What am I doing wrong here? Or what is it that I've missed?
View 4 Replies
Oct 28, 2011
I'm having a casting issue that I am hoping to resolve. I have 2 arrays:
1st array = the clip's parent that I'm trying to target 2nd array = the clip I'm trying to target
When I trace the results, I can see the clip and the clip's parent, they exist on the stage and are qualified. When I try and get the clip by name in part 3, I get an Error #1009.
Can someone lend insight into what I'm doing wrong, or suggest a better way of doing what I'm trying to do?
[Code]...
View 3 Replies
Apr 27, 2010
How i can convert gecko object to a movie clip
function finish(boxname, arrayname:Array):void {
for each (var item:String in arrayname) {
trace(boxname+"_"+item);
[Code]....
View 2 Replies
Nov 9, 2011
I have tree instance calling an iconFunction "getIconFromItem".
<mx:Tree dataProvider="{collection}" iconFunction="getIconFromItem" />
The getIconFromItem function is returning null even though the bitmap is not null.
public function getIconFromItem(item:Object):Class {
var result:Class = item.icon as Class ;
return result ;
}
Setting a break point on the return result line reveals that item.icon is a bitmap and result is null.
how to successfully cast a bitmap as class so that the bitmap is returned as an icon?
View 2 Replies
Dec 9, 2010
I'm trying to convert a generic JSON object into a somewhat complex typed dto-like object that has the following properties:
firstName:String
lastName:String
contactInfo:Vector.<ContactInfo>
resources:Vector.<Resource>
The way I'm doing this is by giving the function metadata which sort of maps the JSON data properties to these data properties and their types, using reflection.So, I have a JSON object that might look something like this:
Code:
{
firstName: "John",
lastName: "Smith",[code].........
and that didn't even compile.
View 0 Replies
Mar 18, 2011
I have a situation where I am trying to build a path to an xml node like this:
Code:
var personName:Object = ["xmLoader.xmlData.profilepage.p"]+num+[".p1name"];
Where "num" is a number passed into to the function. What is happenning is when I trace out personName after this code I get:
"xmLoader.xmlData.profilepage.p2.p1name"
instead of the value that resides at that node name (I can trace out p1name which is John from my processed xml earlier in the code).
View 5 Replies
Sep 20, 2010
I want to make a game which uses a light effect similar to left4kdead (link). I just can't seem to be able to find how this effect is called. It will be strictly 2d top-down view.
View 13 Replies
May 3, 2010
I am trying to create a custom object in AS3 to pass information to and from a server, which in this case will be Red5. In the below screenshots you will see that I am able to send a request for an object from as3, and receive it successfully from the java server. However, when I try to cast the received object to my defined objectType using 'as', it takes the value of null. It is my understanding that that when using "as" you're checking to see if your variable is a member of the specified data type. If the variable is not, then null will be returned.
This screenshot illustrates that I am have successfully received my object 'o' from red5 and I am just about to cast it to the (supposedly) identical datatype testObject of LobbyData:
[Code]...
View 4 Replies
Sep 20, 2011
I have what I think should be a very simple problem. I have an array and can access an element of it like this:
var test = finalArray[0];
Will be a number between 1 and 7
say this will trace a number.No there is a movieclip on the root of stage whose name is a letter (always the same, say "R") and whatever the number is. I'm trying to get this movieclip to gotoAndStop at the frame corresponding to the number that is test. However this isn't working:
"R"+[test as MovieClip.gotoAndStop(test)];
View 3 Replies
Jan 31, 2012
[Code]...
so the problem is I can print the array but how to cast tht array to a known php type? After 5 days I finnaly figured out flex and mysql using amfphp
View 1 Replies
Sep 15, 2010
I have Input text field on Scene with instance name number_txt.[code]
View 9 Replies
Jan 28, 2011
I am using Flex 4 and for whatever reason I cannot get the following code to work which happens inside of a ListEvent handler for a dataGrid:
_tempRule = DataGrid(event.currentTarget).selectedItem as Rule;
Rule is a custom class, and the above code always returns null. The dataprovider for the datagrid is an ArrayCollection. If I try to wrap the above code to make it like the following:
DataGrid(event.currentTarget).selectedItem as Rule
I get this error:
TypeError: Error #1034: Type Coercion failed: cannot convert Object@e15a971 to com.mycompany.arcc.business.Rule
Now I know I have done this before with native Flex classes like Button, etc, but it my case it will not work. Here is the Rule class:
package com.mycompaany.arcc.business {
import flash.utils.describeType;
import mx.collections.ArrayCollection;
[Code] .....
View 2 Replies
Jul 15, 2010
I have a mediator that I've registered for a navigation page:
facade.registerMediator(new NavPageMediator(viewComponent));
I'm trying to retrieve that mediator on another page like so:
var navPageMediator:NavPageMediator = facade.retrieveMediator(NavPageMediator.NAME) as NavPageMediator;
However, that statement returns null. If I try to cast it using the NavPageMediator(facade.retrieveMediator(NavPageMediator.NAME)) syntax instead, I get a TypeError: Error #1034: Type Coercion failed: cannot convert com.website.mvc.view.page::NavPageMediator@237560a1 to com.website.mvc.view.page.NavPageMediator.`
I can't, for the life of me, understand why NavPageMediator@237560a1 would be unable to convert to NavPageMediator, nor what happened in between registering the mediator and retrieving it that caused this. Especially since trace(new NavPageMediator() as NavPageMediator); returns [object NavPageMediator].
Incidentally, and this may be part of my problem, I don't understand what the @hash at the end of the object is (@237560a1). Is it simply an internal identifier for that class instance?
Edit:Left a bit of important info: The SWF in which I instantiate and register the mediator is separate from the SWF in which I try to retrieve it.
View 1 Replies
Dec 6, 2010
I get the error message. Doing like tuts said. package { import flash.events.*; // rememeber to import all flash libraries or the ERROR will come up with "TYPE" does not exist etc.
[Code]...
View 4 Replies
Dec 24, 2010
[Code]....
I'm basically having the following error: 1067: Implicit coercion of a value of type void to an unrelated type Array. In relation to the event listener that calls 'Backdrop'. Backdrop is a public function in another class, but it does still recognise Backdrop as a function.
View 13 Replies