Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how can i make this working? multiple mc instances

Guest
Jul 11, 2014 Jul 11, 2014

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++;

   

}

TOPICS
ActionScript
189
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 12, 2014 Jul 12, 2014

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 12, 2014 Jul 12, 2014

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 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 12, 2014 Jul 12, 2014

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 13, 2014 Jul 13, 2014
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines