View Full Version : mx.utils.Delegate and static functions
fishbellyrust
October 25th, 2005, 04:51 PM
How can I get around using an instance variable in a static function that must be called by the Delegate method?
Anyone?
JimmyH
October 26th, 2005, 04:16 AM
do you have an example of what you mean... i'm under the impression that by the nature of a class method you shouldn't be using instance variables because there is no instance available to access.
fishbellyrust
October 26th, 2005, 11:20 AM
Jimmy, thanks for the response. I have 5 analog world clocks on my stage and I want to show the time via external class files. Here's my code.
//Events.as
//Handles all events
//I create an instance of this object on the first frame of my .fla
//The Delegate method calls the showTime() method in the Clock class
import mx.utils.Delegate;
import ebook.clocks.*;
class ebook.Events {
function Events() {
worldClocks();
}
function worldClocks():Void {
_root.clocks.clockdummy.onEnterFrame = Delegate.create(this, Clock.showTime);
}
}
//
//Clock.as
//Gets the time via showTime() and is called by the Delegate method in Events.as
class ebook.clocks.Clock {
static var _timezones:Array = new Array[5];
var _hrotate:Number = new Number();
var _mrotate:Number = new Number();
function Clock() {
_timezones[1] = 30;
_timezones[2] = 60;
_timezones[3] = 90;
_timezones[4] = 120;
_timezones[5] = 150;
}
function getMinute():Number {
var _time:Date = new Date();
var _s = _time.getSeconds();
var _m = _time.getMinutes();
return(_m*6+(_s/10));
}
function getHour():Number {
var _time:Date = new Date();
var _m = _time.getMinutes();
var _h = _time.getHours();
return(_h*30+(_m/2));
}
static function showTime():Void {
var _hrotate = getHour;
var _mrotate = getMinute;
_root.clocks.clock1.hour._rotation = _hrotate;
_root.clocks.clock1.minute._rotation = _mrotate;
_root.clocks.clock2.hour._rotation = _hrotate;
_root.clocks.clock2.minute._rotation = _mrotate;
_root.clocks.clock3.hour._rotation = _hrotate;
_root.clocks.clock3.minute._rotation = _mrotate;
_root.clocks.clock4.hour._rotation = _hrotate;
_root.clocks.clock4.minute._rotation = _mrotate;
_root.clocks.clock5.hour._rotation = _hrotate;
_root.clocks.clock5.minute._rotation = _mrotate;
}
function changeZone(_clock:Number, _newzone:Number):Void {
_timezones[_clock] = _newzone;
}
}
JimmyH
October 26th, 2005, 11:35 AM
Firstly you shouldn't be using delegate to call a class method because i class method should only access other class methods and class properties which would mean you would never have a scope problem and you wouldn't need to use delegate. But i don't think that's your main problem... i'm not dure what to make of the ebook.clocks.Clock class... is it trying to act as a management class for some movie clips??? i.e. each clock on you stage uses this class.
Your probably best off trying to change this class so that it extends MovieClip and set this class within the linkage options for each mc... so each clock is an instance of the one class... then on the timeline you set the timezone through a public method... each clock will then look different.
Sorry if this is a bit of a head f'ck... i'm not too great at explaining myself... i'll try and knock an example up when i get home a bit later.
Jimmy
JimmyH
October 26th, 2005, 04:03 PM
Right here we go one Clocks class with thre instances on the stage each with a different timezone set by an offsetHours property.. hope this helps a little
download the fla or just take a quick look at the results here
www.vectorjunkie.co.uk/assets/tmpForForum/pages/clocks.htm (http://www.vectorjunkie.co.uk/assets/tmpForForum/pages/clocks.htm)
Jimmy
JimmyH
October 27th, 2005, 04:10 AM
The swf wasn't workin properly.... think i've just fixed it... let me know if anyone has any problems with it.
Jimmy
fishbellyrust
October 27th, 2005, 12:42 PM
Jimmy, this is great, thanks so much!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.