# Calling an Instance's Variables Directly

**URL:** <https://forum.kirupa.com/t/calling-an-instances-variables-directly/292980>\
**Category:** flash\
**Created:** [July 21, 2009, 4:33pm UTC](https://forum.kirupa.com/t/calling-an-instances-variables-directly/292980 "2009-07-21T16:33:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SpoGames](https://avatars.discourse-cdn.com/v4/letter/s/b5e925/32.png) [@SpoGames](https://forum.kirupa.com/u/SpoGames)\
**Post date:** [July 21, 2009, 4:33pm UTC](https://forum.kirupa.com/t/calling-an-instances-variables-directly/292980/1 "2009-07-21T16:33:18Z")

</div>

Ok, here is my question: I have two classes a main and one controlling a cloud graphic going on the stage. In the main class I am creating an instance of the cloud, adding it to the stage with an array and with a for loop I am setting the x speed (vx). I have noticed that if I set the vx in the cloud class and reference it directly then it does not work (clouds are drawn for a millisecond then a blank movie). I have to initialize the cloud.vx value in the main class to get it to work. Why can I not just pull the vx value from the cloud class without setting it to a value in the main class?

Main class

```auto
package
{
	import flash.display.MovieClip;
	import flash.events.*;
	import parts.Cloud_mc;
	
	public class Main extends MovieClip
	{
		public var cArray:Array;
		public var cloudsTotal:uint = 10;
		public var vx:Number = 2;
		
		public function Main()
		{
			init();
		}
		public function init()
		{
			cArray = new Array()
			for(var i = 0; i < cloudsTotal; i++)
			{
				var cloud:MovieClip = new Cloud_mc();
				cloud.x = Math.random() * stage.stageWidth;
				cloud.y = Math.random() * stage.stageHeight;
				//cloud.vx = Math.random(); If I initialize the code here it works
				addChild(cloud);
				cArray.push(cloud);
			}
			
			stage.addEventListener(Event.ENTER_FRAME, eFrame);
		}
		public function eFrame(event:Event):void
		{
			for(var i = 0; i < cArray.length; i++)
			{
				var cloud:Cloud_mc = cArray*;
				[COLOR="Red"]cloud.x += cloud.vx;[/COLOR]
			}
		}
	}
}

```

Cloud class

```auto
package parts
{
	import flash.display.MovieClip;
	
	public class Cloud_mc extends MovieClip
	{
		public var vx:Number = 4;
		
		public function Cloud_mc(a:Number, w:Number, h:Number)
		{
				
		}
	}
}

```
