# AS3 - Access class functions from inside an instance

**URL:** <https://forum.kirupa.com/t/as3-access-class-functions-from-inside-an-instance/295450>\
**Category:** flash\
**Created:** [August 30, 2009, 4:14pm UTC](https://forum.kirupa.com/t/as3-access-class-functions-from-inside-an-instance/295450 "2009-08-30T16:14:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![cordlesspaper](https://avatars.discourse-cdn.com/v4/letter/c/3ab097/32.png) [@cordlesspaper](https://forum.kirupa.com/u/cordlesspaper)\
**Post date:** [August 30, 2009, 4:14pm UTC](https://forum.kirupa.com/t/as3-access-class-functions-from-inside-an-instance/295450/1 "2009-08-30T16:14:45Z")

</div>

I am attempting to create a fluid layout which will house a rather wide animation. I want to be able to set variables from inside the timeline of the instance of the class.

## Class for creating a fluid object on the stage

```auto
package FluidLayout{
	
	/* Add import classes here */
	import flash.events.Event;
	import flash.display.*;
	
	public class FluidObject{  

        /* Declare instance variables here */ 
		protected var _param:Object;
		protected var _target:DisplayObject;
		protected var _stage:Stage;
		

        public function set param(value:Object):void
		{
			_param = value;
			this.reposition();
		}

		/* Constructor of the class */  
        public function FluidObject(target:DisplayObject,paramObj:Object)  
        {
			_target = target;
			_param = paramObj;
			_stage = target.stage;
			
			_stage.addEventListener(Event.RESIZE, onStageResize);
			this.reposition();
        }  

        /* Function that repositions the monitored object */  
        protected function reposition():void  
        {  
			var stageW = _stage.stageWidth;
			var stageH = _stage.stageHeight;
			
			trace(_param.offsetX); 

			_target.x = (stageW * _param.x) + _param.offsetX;
			_target.y = (stageH * _param.y) + _param.offsetY;
        }  

        /* Function that is called when the RESIZE event is fired */  
        protected function onStageResize(e):void  
        { 
			this.reposition();
        }
    }  
}  

```

* * *

## This is the structure.as that is linked to structure.fla

```auto
package {  
  	  
    import flash.display.*;
    import FluidLayout.*;

    public class Structure extends MovieClip{  

        public function Structure()  
        {  
            /* Set the Scale Mode of the Stage */  
            stage.scaleMode = StageScaleMode.NO_SCALE;  
            stage.align = StageAlign.TOP_LEFT;  
			 
			var viewer = new Viewer();
			addChild(viewer);

			var viewerParam = {  
				x:.5,
				y:.5,
				offsetX: -viewer.width/2,
				offsetY: -viewer.height/2
			}  
			new FluidObject(viewer,viewerParam);           
        }  
    }  
}  

```

## Inside the structure.fla there is movieclip called viewer that gets placed with structure.as. Viewer contains animations. Inside the viewer movieclip on frame one is the following actionscript

```auto
this.param = {offsetX: -870};

```

* * *

What I am trying to accomplish is to create a fluid layout that runs an animation sequence.  
The animation sequence is quite wide so it’s X position shifts during the course of it’s run.  
I need to adjust that offsetX to match the animations x position otherwise when the stage  
gets resized it snaps the animation x position back to 0.

The problem is I get no errors but the offsetX is definitely not changing. Am I going about this the wrong way? Where am I going wrong here?
