Sunday, April 25, 2010

Access of MainTimeline to class file

Here is code for How to access MainTimeline objects in fla to .as class file.

In main.fla,
There are two text boxes SentText and gettext.
code is:

import com.sample

var sample:Sample=new Sample(this)
sample.SentText("Sent to Class File")
gettext.text=sample.GetText();

Here this keyword  represents MainTimeline, to class sample , when instance of that class is created.

in Sample.as

package com
{
public class Sample
{
private var SuperObject:Object;
public function Sample(mySuperObj:Object)
{
SuperObject=mySuperObj;
}
public function SentText(str:String)
{
SuperObject.Mytext.text=str
}
public function GetText():String
{
return SuperObject.Mytext.text;
}
}
}


Here SuperObject is a variable of type Object , which represent MainTimeLine.
When object of class Sample is created, MainTimeline is passed to Sample Class constructor.
If we trace (SuperObject) it shows [object MainTimeline].
If you write this code in document Class, this document Class represent MainTimeLine
and now we can access of objects of MainTimeLine as seen.

Thanx;
Enjoy Actionscripting..........

No comments:

Post a Comment