ActionScript 3.0 :: Create Dynamic Vector Strict Type?
Nov 8, 2010Below does not work
PHP Code:
var c:Class = Sprite;
var v:Vector.<c> = new Vector.<c>();
Below does not work
PHP Code:
var c:Class = Sprite;
var v:Vector.<c> = new Vector.<c>();
Typically you create a Vector (strongly typed array) specifying a data type like:
new Vector<PictureBox>();
However I need to create a utility method that should be able to create a vector of any given datatype. Is it possible to specify a type using a variable instead of hard-coding it?
var type:Class = PictureBox;
new Vector<type>();
i tried searching for an answer but no luck..i know i can enforce type checking by writing:
ActionScript Code:
var iCount:Number = 10;
but for existing objects, while adding properties to them, i cannot specify datatypes:
[code].....
i want to use a variable to load a mc [code]when i use "string", it works locally but not uploaded on the server
View 1 RepliesI need to create a custom Object that basically stores some custom parameters (properties?), which I have successfully done, and the code below works fine.
PHP Code:
myObject = new Object();
myObject.nameLabel = "New Releases";
myObject.artOrientation = "portrait";
myObject.artAmount = 5;
I find the new compiler and debugger capabilities very useful, since I'm not the most detail-oriented, so I (usually) like that Flash forces me to strict-type my variables and such. Anyway, I was wondering if it's a "best practice" to strict data type a custom objects' properties, and if so, how to do it in the logic above? I kept getting syntax errors when I just tried it initially.
I know if I created a custom Class .AS file, I would be forced to data type the properties... but I'd rather just do it "in-line" in my main .FLA file. Also, I know I can just pass typed VARIABLES to the properties... but I'd rather have the properties strict-typed themselves... so if I try to pass a variable as the wrong type, then I would still get an error.
I want to write some util functions for the Vector type, like concat_unique(v1:Vector, v2:Vector):Vector ... etc But I am coming across the problem of passing in a generic Vector to a function. I have tried:
[Code]...
Below is basic structure of LetterClip class which extends WMovieClipwhich inreturns extends Movieclip Class.
public class LetterClip extends WMovieClip
{
public function LetterClip(char:String):void
[code]...
Error occurs at the push statement.It throws the given below error only when the same activity is executedsecond time in a sequece.
TypeError: Error #1034: Type Coercion failed: cannot convertorg.waterford.activity.erp.erp1.r1lt08.clipclass::LetterClip@282e9281 to org.waterford.activity.erp.erp1.r1lt08.clipclass.LetterClip.#Operating System: Windows XPBrowser: Microsoft IE
I have a quick question for you all. I'm trying to convert over some ActionScript code to C++ and am having a difficult time with this one line:
private var edges:Vector.<Array> What is this exactly? Is this essentially a multidimensional vector then? Or is this simply declaring the vector as a container? I understand from researching that vectors, like C++ vectors, have to be declared with a type. However, in C++ I can't just put down Array, I have to use another vector (probably) so it looks like:
I don't expect you guys to know the C++ equivalent because I'm primarily posting this with AS tags, but if you could confirm my understand of the AS half, that would be great. I did some googling but didn't find any cases where someone used Array as it's type.
I have a class which takes a Vector.<DisplayObject> in it's constructor. I had expected it to be ok to create instances of this class by passing Vectors of types that are subclasses to the DisplayObject class (in this case Sprite ans SimpleButton). But it doesn't work. And casting these Vectors as Vector.<DisplayObject> when declaring the instances doesn't work either. [code]...
View 1 RepliesTrying to create a 2D vector. I'm getting type coercion errors when trying to store the 2nd vector inside the first.
Code:
var vector1:Vector.<Vector> = new Vector.<Vector>
var vector2:Vector.<CustomClass> = new Vector.<CustomClass>
for(var i:int=0;i<5;i++){
vector2[i] = new CustomClass()
}
vector1[0] = vector2;
1067: Implicit coercion of a value of type __AS3__.vec:Vector.<CustomClass> to an unrelated type __AS3__.vec:Vector.
I have a class member in an ActionScript 3 class that looks something like this:
private var m_myvect :Vector.<MyType> = new <MyType>[];
I'm exposing it through a getter, like this:
public function get mydata() :Vector.<MyType>
Which doesn't help when I use it like this:
for (var o:Object in inst.mydata)
{
...
}
... because the type of o is not MyType, but Number instead, because it enumerates the vector indices instead of the data.How would I expose only the data within the vector in a way which:Does not expose the data in a way which allows it to be modified?
I need to know the best method to find an item inside a list (Vector, Array, Dictionary, whatever is faster) of complex type (extensions of Objects and Sprites).I've used "Needle in Haystack" method, but it seems that it isn't fast enough.
E.g.Suppose that I have a collection of Sprites (a pool, in fact).Each sprite will be added to the stage and perform some action. After that, it will die.I don't want to pay the cost to dispose it (garbage collect) and create another (new) one every time so I'll keep the dead sprites in a collection.
Sometimes times I'll call a method that will add a sprite to the stage.This sprite can be a old one, if it is already dead, or a new one, if the pool don't have any free sprite.
One of the scenarios that pushed me to this question was a Particle System.A "head" particle leaving a "trail" of particles every frame and exploding into a flashy multitude of particles... Every frame...Some times this counts up to 50.000 PNGs with motion, rotation, alpha, event dispatching, scale, etc...But, this is JUST ONE scenario...At the moment I'm trying to use a Object Pool with a Linked List...Hopes that it will be faster that running a whole Array/Vector or create new instances every frame an let them dye with Garbage Collection.
I need to know how to create(convert) to vector text from text created from Text Tool from Flash CS4.
View 5 RepliesI'm looking for method to create Vector and push some values without defining variable Vector. For example:I have function:
public function bla(data:Vector.<Object>):void { ... }
this function expects Vector as parameter. I can pass parameters this way
var newVector:Vector.<Object> = new Vector.<Object>();
[code].....
First: When creating a Vector, does it have to contain a Flash data type (uint, int, Number) or can I have a Vector of objects I created classes for?
Second :I cannot instantiate a Vector object. All of the documentation I am finding is saying[code]
I get "1084: Syntax Error: expecting identifier before lessthan". I was thinking that maybe I needed to include a library, but the error seems like it knows that I am trying to create a Vector.
I'm trying to create a vector of a class... i'm. writing this code
Code:
var size:Number = 10;
var testVec:Vector.<classB> = new Vector.<classB>(size);
so when i try to use this vector in some funcion like this
[Code].....
do u guys have any idea how this: [URL] vector animation is done?
View 3 RepliesIs it possible that multidimension vector work this way by creating new value into vector dynamically, not fixed array size as multidimension array does?Such as below array where [0] will create new array ['24']['25'] more than [1][code]How do I get how many array on row[0]?
View 1 RepliesI'm currently building a create-your-own t-shirt application using AS3. My client needs the resulting design as an Adobe Illustrator file for printing. Is there a way to dynamically create an AI file from your Flash app? The only solution I have been able to come up with is recreating the design in a special version of the app that only the client has access to (the app would automatically load and create what the customer designed). This version of the app uses PrintJob to create a printable version of the design that the client saves to a PDF and then opens in Illustrator. It works, but as you can see, it's a messy process and creates additional steps for the client.
View 1 RepliesI'm getting
ActionScript Code:
1067: Implicit coercion of a value of type
__AS3__.vec:Vector.ie.aro.floorplanviewer.model.buildingVOs:ConfigurationVO>[code]....
which surprises me as ConfigurationVO inherits from NodeVO.Is the compiler really not able to figure out that a Vector of a superclass should be able to hold a reference to a Vector of a subclass?
I need to import a bunch of vector work from Photoshop into Flash. Is there a trick to it. So far, on import, it's converting the layer styles into black.
View 5 RepliesIf I want to pass in a vector to a function, a vector of any object specifed would it be someVetor:Vetor.<T>? beause FB 4.5 sais T is undefined.
View 10 RepliesCreated Vector with the initial length of 100.
var v:Vector. = new Vector.(100);
v[90] = "Ninety"
v[190] ="oneninety" //RangeError: Error #1125: The index 110 is out of range 100.
//How to change the length from 100 to 200 to store a value at index 190
I was writing some stuff today and i realized that variables inside a class are not constrained to the constructor or method scope. In my opinion this is utter lazynes. Scopes need to be fully enforced to force programmers to comply with correct OOP styles and organization.
to force yourslef to comply with the standards, when reffering to the consturctor always use the 'this' prefix and use 'var' for all temporary variables that should be inside the method scope.
Is there any way to set actionscript compiler in strict mode? I had to check the size of an array in a function.[code]I've lost a lot of time (lenght is an undefined property and if condition was not verified, so function went on... so bad!). Is there any way to force compiler to stop and warn me in this or similar cases?
View 3 RepliesI am learning ActionScript 3.0. Coming from Java world I can easily relate to strict compilation mode. I think having type safety checks at compilation time makes perfect sense. This makes me wonder, why the compiler allows a standard mode were all the type safety checks are deferred to run time? Is compatibility with older ActionScript specification the sole reason for having standard mode?
View 2 RepliesI am currently being confused by the Vector class.I wrote a beautiful XML to TypedClass parser. Works beautifully and without fault. UNTIL a co-worker noticed we got a Conversion Error for Vector.<Number> to Vector.<*>.
Every Vector I've ever tested all extend Vector.<*>.
Vector.<Sprite>, Vector.<String>, Vector.<Point>, Vector.<Boolean>, Vector.<TextField>, Vector.<CustomObject>, etc etc etc. ALL of them.
<type name="__AS3__.vec::Vector.<String>" base="__AS3__.vec::Vector.<*>" isDynamic="true" isFinal="false" isStatic="false">
<extendsClass type="__AS3__.vec::Vector.<*>"/>
[code]...
But then when I use describeType on Vector.<Number>, Vector.<uint> and Vector.<int>.
<type name="__AS3__.vec::Vector.<Number>" base="Object" isDynamic="true" isFinal="true" isStatic="false">
<extendsClass type="Object"/>
<constructor>
[code]....
Now I have accounted for these 3 vectors individually as even uint and int does not extend Vector.<Number> as I would have expected.
And my parsing function works for all types correctly again. But my confusion comes as to WHY this is the case, and why I couldn't find any documentation on the subject.
I'm struggling with the transition to AS3, specifically not being able to use parent like I used to. Aside from it making me a better coder, are there any good reasons to use strict mode? If I dont use it, are there any 'side effects' to my swf I should be aware of? Any input on parent and strict mode.
View 5 RepliesI'm looking for will all happen in about two or three seconds. I'm re-building my own website using AS3 package classes. When the API loads I want everything to appear in sequence from invisible to visible. First the logo, a few lines drawing themselves, then all the navigation buttons at the top appearing in a quick-fire horizontal row, then the content rolls in, etc. I want strict, accurate control over about two or three seconds, of how and when everything on stage goes from invisible to visible in a quick-fire sequence. I know it can all be done with several timers for each alpha going from 0 to 1. But can all the variables going from alpha 0 to 1 be bundled into an Array? And the Array fired by ONLY ONE Timer using a For Loop? Or am I just barking up the wrong tree? Should I just use a bunch of Timers? I want to avoid a Tween because I want very accurate control of the quick-fire invisible to visible effect. And I want it to be easy to change later. Can this effect be done by ONLY ONE Timer rather than several Timers? And if it can, how do I make the timer fire all variables in strict sequence? Do I use an Array with a For Loop? Or something else? I've been looking for a couple of days but still haven't found anything close.
View 2 RepliesI have an application which receives dynamic XML data from a server. The structure of the XML is dynamic and the tags/attribute names cannot be predicted. NO row items can be hardcoded. The data is coming back from a database (imagine columns and rows), and the type of the data is known on the server side. The following is just an example, an only shows the structure of how the data comes back.
[Code]...