# Dynamic Data Typing

**URL:** <https://forum.kirupa.com/t/dynamic-data-typing/186823>\
**Category:** Uncategorized\
**Created:** [April 24, 2006, 9:06pm UTC](https://forum.kirupa.com/t/dynamic-data-typing/186823 "2006-04-24T21:06:06Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelxxOA](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@MichaelxxOA](https://forum.kirupa.com/u/MichaelxxOA)\
**Post date:** [April 24, 2006, 9:06pm UTC](https://forum.kirupa.com/t/dynamic-data-typing/186823/1 "2006-04-24T21:06:06Z")

</div>

Here is something for you to play around with…

I will give you a little idea… and see what you guys can do to come up with stuff.

The only reason I’m not going to go into detail with this is, I gotta keep some of us programmers job security safe ;). This is merely to inspire.

```auto

var myClass:Function = Array;

var myArray:Object = new myClass();

trace( myArray instanceof myClass);

myArray.push(5);
myArray.push(10);

trace( myArray );

```

I may come back with a more elaborate example… but I may not… enjoy

TakeCare…  
\_Michael

---

<div class="post-metadata">

**Author:** ![MichaelxxOA](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@MichaelxxOA](https://forum.kirupa.com/u/MichaelxxOA)\
**Post date:** [April 24, 2006, 9:08pm UTC](https://forum.kirupa.com/t/dynamic-data-typing/186823/2 "2006-04-24T21:08:21Z")

</div>

of course this is coming from the guy who lost his job this week…

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [April 24, 2006, 9:11pm UTC](https://forum.kirupa.com/t/dynamic-data-typing/186823/3 "2006-04-24T21:11:20Z")

</div>

lol… bastard.

---

<div class="post-metadata">

**Author:** ![MichaelxxOA](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@MichaelxxOA](https://forum.kirupa.com/u/MichaelxxOA)\
**Post date:** [April 24, 2006, 9:15pm UTC](https://forum.kirupa.com/t/dynamic-data-typing/186823/4 "2006-04-24T21:15:19Z")

</div>

lol… well here’s one example… that I’ll **TELL** you…

I have a collection that is similar to a generic in Java… or similar to arrays in java with the lack of implementation

It’s a collection that can be typed, will only hold the Type you specify.

Happy Programming 🙂

\_Michale

---

<div class="post-metadata">

**Author:** ![gvozden](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/gvozden/32/1084_2.png) [@gvozden](https://forum.kirupa.com/u/gvozden)\
**Post date:** [April 25, 2006, 12:55am UTC](https://forum.kirupa.com/t/dynamic-data-typing/186823/5 "2006-04-25T00:55:09Z")

</div>

something that I’ve done in Modula-2 doesn’t inspire me doing with AS  
maybe when I need it I will  
so what’s next 😉

---

<div class="post-metadata">

**Author:** ![MichaelxxOA](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@MichaelxxOA](https://forum.kirupa.com/u/MichaelxxOA)\
**Post date:** [April 25, 2006, 8:58am UTC](https://forum.kirupa.com/t/dynamic-data-typing/186823/6 "2006-04-25T08:58:03Z")

</div>

Here is the first example…

**GenericCollection.as**

```auto

/**
 * An example file for our generic collections class..
 *
 * @author Michael Avila
 * ...
 * @version 1.0.0
 */
class GenericCollection
{

	// the datatype that this collection holds
	private var thetype:Function;

	// the collection interior
	private var collection:Array;

	/**
	 * Constructor
	 *
	 * @param The datatype this collection will hold
	 */
	public function GenericCollection( datatype:Function )
	{

		if (datatype == undefined)
		{
			trace("Constructor GenericCollection requires parameter datatype");
		}
		thetype = datatype;
		collection = new Array();
	}

	/**
	 * Adds an item to the collection... must be of the specified type
	 */
	public function add( object:Object ):Boolean
	{
		if ( !(object instanceof thetype) )
		{
			trace("Invalid type: Class GenericCollection");
			return false;
		}
	   	var len:Number = collection.length;
	   	for (var i:Number = 0; i < len; i++)
		{
			if (collection* == object) return false;
		}

		collection.push( object );
		return true;
	}

	/**
	 * Returns the object at the specified index.
	 */
	public function get( index:Number )
	{
		return thetype( collection[index] );
	}

	/**
	 * Removes the item from the collection
	 */
	public function remove( object:Object ):Object
	{
		var len:Number = collection.length;
		for (var i:Number = 0; i<len; i++)
		{
			if ( collection* == object ) return collection.splice(0, 1);
		}
	}

	/**
	 * Removes the item at the specified index
	 */
	public function removeAt( index:Number ):Object
	{
		return collection.splice(index, 1);
	}
}

```

Here is it’s usage so far in the fla

```auto

var gcol = new GenericCollection( Array );

trace( gcol.add( new Array(5, 10, 15) ) );
trace( gcol.add( new Object() ) );

trace( gcol.removeAt(0) );

```

Feel free to ask anyquestions.

TakeCare  
\_Michael

---

<div class="post-metadata">

**Author:** ![MichaelxxOA](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@MichaelxxOA](https://forum.kirupa.com/u/MichaelxxOA)\
**Post date:** [April 25, 2006, 9:49am UTC](https://forum.kirupa.com/t/dynamic-data-typing/186823/7 "2006-04-25T09:49:40Z")

</div>

The only thing I’m having a hard time overcoming is that this will not work with primitive data types (Number, String, Boolean).

TakeCare  
\_Michael

---

<div class="post-metadata">

**Author:** ![ramie](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@ramie](https://forum.kirupa.com/u/ramie)\
**Post date:** [April 25, 2006, 4:30pm UTC](https://forum.kirupa.com/t/dynamic-data-typing/186823/8 "2006-04-25T16:30:46Z")

</div>

number, string and boolean are abstract datatypes not primative

---

<div class="post-metadata">

**Author:** ![MichaelxxOA](https://avatars.discourse-cdn.com/v4/letter/m/9dc877/32.png) [@MichaelxxOA](https://forum.kirupa.com/u/MichaelxxOA)\
**Post date:** [April 25, 2006, 5:17pm UTC](https://forum.kirupa.com/t/dynamic-data-typing/186823/9 "2006-04-25T17:17:56Z")

</div>

Where exactly did you hear that?

The specification states that the following are primitive data types:

Boolean  
null  
Number  
String  
undefined

I am not saying that you are wrong, I would just like to know.

TakeCare  
\_Michael

---

<div class="post-metadata">

**Author:** ![ramie](https://avatars.discourse-cdn.com/v4/letter/r/edb3f5/32.png) [@ramie](https://forum.kirupa.com/u/ramie)\
**Post date:** [April 25, 2006, 6:34pm UTC](https://forum.kirupa.com/t/dynamic-data-typing/186823/10 "2006-04-25T18:34:40Z")

</div>

The spec may state that they are, but thats quite wrong - because they have methods provided that allow you to operate on the data contained, this makes them abstract.

From the language def…

The String class is a wrapper for the string primitive data type, and provides methods and properties that let you manipulate primitive string value types.

The Number class is a simple wrapper object for the Number data type - number cant be a primitive, how can a primitive handle, int, bigint, double, single and so on…

The Boolean class is a wrapper object with the same functionality as the standard JavaScript Boolean object.

and so on…

I’m just being pedantic and you probably meant string rather than String, I should probably be ignored lol, but a primitive is completely different, it is a base type that provides a container for data with a certain amount of bytes allocated in the stack when its created, the abstraction happens when you add functionality to this base type, ala String and so on…
