Toon posts:

[Flash AS 2.0] Callback probleem

Pagina: 1
Acties:

Verwijderd

Topicstarter
hello ...
ik kom er maar niet uit... Ik probeer een class te schrijven met een timeout. Het idee is dit : Ik wil vanaf de timeline een timeout aanroepen en als die klaar dat ti een event opgooit en op de timeline reageert ti op die event.

dit is mijn class :

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
    Timeout class
    Fransjo Leihitu
    http://www.leihitu.nl
*/
dynamic class Matahari.util.timeOut {
    
    var addListener:Function;
    var removeListener:Function;
    
    var objRef:Object;
    
    public function timeOut(objReference:Object)
    {
        super(this);
        
        if(objReference!=null)
        {
            AsBroadcaster.initialize(this);
            objRef=objReference;
        }       
    }
    
    public function setTimeOut(timoutMiliseconds:Number):Void
    {
        if(objRef!=null)
        {
            // add the listener
            this.addListener(objRef);
            
            trace("starting Timeout");
            intervalId=setInterval(doneTimeOut,timoutMiliseconds);
        }
    }
    
    public function doneTimeOut()
    {
        trace("done Timeout");

        // stop the timeout
        clearInterval(intervalId);
        
        // Tell all listeners the timeout is over
        this.broadcastMessage("onDoneTimeout",true);
    }   
}


en de aanroep vanaf mijn time line :

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
import Matahari.util.timeOut;

var objCallback:Object;
objCallback=new Object();
objCallback.onDoneTimeout=function(bRresult:Boolean){
    trace("from Timeline");
}

var timeOutObj:timeOut;
timeOutObj=new timeOut(objCallback);
timeOutObj.setTimeOut(1000);

stop();


ik krijg dus wel als output :

code:
1
starting Timeout


en 1 seconde later krijg ik keurig

code:
1
done Timeout


maar geen

code:
1
from Timeline



wtf doe ik fout?

HELP?

Verwijderd

Topicstarter
laat maar heb de fout gevonden ...

intervalId=setInterval(this,"doneTimeOut",timoutMiliseconds);

moest het zijn ....

Verwijderd

Topicstarter
Ok hij werkt .... Maar iemand had me een tip gegeven en heb me class herschreven :

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
    Timeout class
    Fransjo Leihitu
    http://www.leihitu.nl
*/
dynamic class Matahari.util.timeOut1 {
    
    var addListener:Function;
    var removeListener:Function;


    public function timeOut1()
    {
        super(this);
        
        AsBroadcaster.initialize(this);
        this.addListener(this);
    }
    
    public function setTimeOut(timoutMiliseconds:Number):Void
    {
        intervalId=setInterval(this,"doneTimeOut",timoutMiliseconds);
    }
    
    public function doneTimeOut()
    {
        // stop the timeout
        clearInterval(intervalId);
        
        // Tell all listeners the timeout is over
        this.broadcastMessage("onDoneTimeout",true);
    }
}



en op de timeline


code:
1
2
3
4
5
6
7
8
9
import Matahari.util.timeOut1;

var timeOutObj:timeOut1 = new timeOut1();
timeOutObj.onDoneTimeout = function(bRresult:Boolean) {
    trace("from timeline");
}
timeOutObj.setTimeOut(1000);

stop();



Dit werkt ook. Dus de class zelf (de broadcaster) is gelijk ook een listener. Is dit een geldig OOP?