Copy link to clipboard
Copied
i wonna make a little game..
you have to hit the red circle, you have 3 seconds for it. the new circle shows up after one sec but the old ones should stay there cuz of the 3 seconds you got to hit it. if you dont hit each red circle in this 3 seconds it should be over and the score should show up but that does not work how it should aither cuz of the same problem. its a little bit more complex than i thought.
maybe you wonna take the code to try it.
i dont know how to make it working the most efficient way.
thanks for any help.
here is my code so far:
var myTimer:Timer = new Timer(1000,0);
// Event listeners:
myTimer.addEventListener("timer", myTimerAction);
//myTimer.addEventListener("timerComplete", myTimerComplete);
myTimer.start();
var count:Number = 0
var _mc:MovieClip = new MovieClip();
var errorTimer:Timer = new Timer(3000,1);
// Event handlers:
function myTimerAction(event:TimerEvent):void
{
trace(event.target.currentCount+" mal ausgelöst.");
// der Code
// der alle x Millisekunden
// ausgeführt wird.
// Event listeners:
errorTimer.addEventListener("timer", errorTimerAction);
errorTimer.addEventListener("errortimerComplete", errorTimerComplete);
errorTimer.start();
// Event handlers:;
function errorTimerAction(event:TimerEvent):void
{
myTimer.stop();
ergebnis.text = (count+" hast du geschafft");
}
function errorTimerComplete(event:TimerEvent):void
{
trace("Timer wird entfernt.");
errorTimer.removeEventListener("timer", errorTimerAction);
errorTimer.removeEventListener("timerComplete", errorTimerComplete);
}
var yrandomNum:Number = yrandomRange(70,947);
//y axenwert zufällig
function yrandomRange(minNum:Number, maxNum:Number):Number
{
return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
}
var xrandomNum:Number = xrandomRange(70,570);
//x axenwert zufällig
function xrandomRange(minNum:Number, maxNum:Number):Number
{
return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
}
function CustomCircle(xInput:Number,yInput:Number,rInput:Number,colorInput:uint)
{
_mc.graphics.beginFill(colorInput);
_mc.graphics.drawCircle(xInput, yInput, rInput);
}
CustomCircle(-35,35, 60, 0xFF3A00);
_mc.x = xrandomNum;
_mc.y = yrandomNum;
_mc.name = "mcButton";
addChild(_mc);
}
/**function myTimerComplete(event:TimerEvent):void
{
// Es ist immer eine gute Idee, Event listeners
// zu entfernen, wenn sie nicht mehr benötigt
// werden:
trace("Timer wird entfernt.");
myTimer.removeEventListener("timer", myTimerAction);
myTimer.removeEventListener("timerComplete", myTimerComplete);
}
**/
_mc.addEventListener(MouseEvent.CLICK, wennduklickst);
function wennduklickst(event:MouseEvent):void
{
removeChild(_mc);
errorTimer.stop();
count++;
}
Copy link to clipboard
Copied
If you intend for each object to be timing out then each object needs it's own errorTimer.
You should not be nesting all of those named functions inside the myTimer Action function. Break them out to stand on their own.
Copy link to clipboard
Copied
ok.. i will try my best but as you can imagine i am a layman and i just try to do this by my self so i dont know a lot of the basic´s till now.
so, if i am breaking this named functions out of the myTimer Action, i suggest by righting them above the timer
and just calling them from inside the timer, the problem with the disapearing circle can be solved?
or do i have to generate another circle with a new name and a new errortimer to make it working?
i dont have an idea how to make this as easy as possible. i think i will make just a name variable for the _mc name that should be created.
like name it _mc but if the name _mc is already on the stage name it _mc2, if that is allready on the stage call it _mc3 and so on...
can you or anybody let me know if i am on the right track or give me a hint?
thank you a lot for your help 🙂 i owe you one, and the guys that made the internet workin 🙂
Copy link to clipboard
Copied
I would create each abject that needs to be clicked to have its own code/Timer so that they are self-managing as far as timing out goes. You can still have the clicking of them managed at the main file level.
Copy link to clipboard
Copied
i tryed it another way. i found an oportunity to make a dynamic variable so everything is working, just the wennduklikst Eventlistener at the end of the code is not working anymore now. but it should. maybe you know the anser!!??.
var count:Number = 0
var _mc:Array = new Array();
for(var i:int = 0; i<=100; ++i)
{
var _mc0:MovieClip = new MovieClip();
this.addChild(_mc0);
// now add your square object to our Array
_mc.push(_mc0);
}
//var _mc0:MovieClip = new MovieClip();
var _errortimer:Array = new Array();
for(var i2:int = 0; i2<=100; ++i2)
{
var _errortimer0:Timer = new Timer(3000,1);
//addChild(_errorTimer0);
// now add your square object to our Array
_errortimer.push(_errortimer0);
}
//var errorTimer:Timer = new Timer(3000,1);
// 3000 = Zeit zwischen zwei Timeraufrufen in Millisekunden
// 0 = Anzahl der Wiederholungen (0 = unendlich oft)
var myTimer:Timer = new Timer(1000,1);
// Event listeners:
myTimer.addEventListener("timer", myTimerAction);
//myTimer.addEventListener("timerComplete", myTimerComplete);
myTimer.start();
// Event handlers:
function myTimerAction(event:TimerEvent):void
{
trace(event.target.currentCount+" mal ausgelöst.");
// der Code
// der alle x Millisekunden
// ausgeführt wird.
// Event listeners:
_errortimer[0].addEventListener("timer", errorTimerAction);
_errortimer[0].addEventListener("errortimerComplete", errorTimerComplete);
_errortimer[0].start();
// Event handlers:;
function errorTimerAction(event:TimerEvent):void
{
myTimer.stop();
ergebnis.text = (count+" hast du geschafft");
}
function errorTimerComplete(event:TimerEvent):void
{
trace("Timer ,,wird entfernt.");
_errortimer[0].removeEventListener("timer", errorTimerAction);
_errortimer[0].removeEventListener("timerComplete", errorTimerComplete);
}
function CustomCircle(xInput:Number,yInput:Number,rInput:Number,colorInput:uint)
{
_mc[0].graphics.beginFill(colorInput);
_mc[0].graphics.drawCircle(xInput, yInput, rInput);
}
CustomCircle(-35,35, 60, 0xFF3A00);
_mc[0].addChild
var yrandomNum:Number = yrandomRange(70,947);
//y axenwert zufällig
function yrandomRange(minNum:Number, maxNum:Number):Number
{
return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
}
var xrandomNum:Number = xrandomRange(70,570);
//x axenwert zufällig
function xrandomRange(minNum:Number, maxNum:Number):Number
{
return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
}
_mc[0].x = xrandomNum;
_mc[0].y = yrandomNum;
_mc[0].name = "mcButton";
//addChild(_mc);
}
/**
function myTimerComplete(event:TimerEvent):void
{
// Es ist immer eine gute Idee, Event listeners
// zu entfernen, wenn sie nicht mehr benötigt
// werden:
trace("Timer wird entfernt.");
myTimer.removeEventListener("timer", myTimerAction);
myTimer.removeEventListener("timerComplete", myTimerComplete);
}
**/
_mc[0].addEventListener(MouseEvent.CLICK, wennduklickst);
function wennduklickst(event:MouseEvent):void
{
_mc[0].removeChild
_errortimer[0].stop();
count++;
}
thanks a lot
Find more inspiration, events, and resources on the new Adobe Community
Explore Now