1

HI all, i have a class file named Main.as and another class calledr icon.as

package {

    import icon;
    public class main {
        public var _time:String;
        function main() {

            _time="01:10";
            iconObj=new icon(this);

        }
        function timerFunction() {
            _time=newTime;
        }
    }
}

package {

    public class icon {
        public var mytime:NUmber;
        function icon(mainObj:*) {

            trace("My time "+mainObj._time)

        }

    }
}

//sample outout

// My time 01:10

How do i get the current update from the main class without calling the MainObj repeatedly. Is this possible in Flash AS3, or any other alternate method for this idea.

2 Answers 2

1

Check out the Observer Pattern. You can have a clock which notifies its observers once the time changes.

Ther are already libraries simplifing this job for you like as3-signals. You can also use flash.events.EventDispatcher for the same task.

Sign up to request clarification or add additional context in comments.

2 Comments

actually i dont want to trigger the timer from the main clas. I need to check this from icon.as file. at a specific point i need to get the time from main class.. i think now you understood what i want :)
If you "need to get the time from main class" you will have to ask for it, like "mainObj.time".
0

Store a reference to the Main class object locally in Icon

package 
{
    public class Icon 
    {
        public var mytime:NUmber;
        //store an instance of Main obj here.
        public var mainObj:Main;
        public function Icon(mainObj:Main) 
        {
           this.mainObj = mainObj;
        }
        //call this method whenever you want time
        public function readTime():void
        {
           trace("My time " + mainObj._time);
        }
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.