Skip to main content
Inspiring
January 21, 2015
Answered

In what order are these actions being done?

  • January 21, 2015
  • 1 reply
  • 815 views

In this code I haven't used a loader but JUST to let the user realize that something is going on, when user clicks on "next" and a huge class in going to function, I firstly show a "loadingScreen" that simply says LOADING and then call that huge function "mazeDisp.creatMaze()"....

My problem is that why the loadingScreen is not shown before that function is being called!!!

function nextClicked(e:MouseEvent):void {

    menu.visible = false;

    pauseBtn.visible = false;

    loadingScreen.visible = true;  //HERE I NEED IT TO BE SHOWN BUT WON'T

    addChildAt(ipad0,0);

    ipad0.addChildAt(mazeDisp,0);

    ipad0.addChildAt(ipad1,0);

    ipad1.addChildAt(ipad2,0);

    mazeDisp.clearb2World();

    mazeDisp.createMaze(75,100,8);  //THIS IS THAT HUGE FUNCTION (of another class) WHICH INCLUDES A LOT OF Box2D Classes.

}

function readyHandler(e:Event):void {

    menu.visible = false;

    loadingScreen.visible = false;  //HERE I HIDE IT AGAIN

    pauseBtn.visible = true;

    isPlaying = true;

    addEventListener(Event.ENTER_FRAME, frameHandler);

}

This topic has been closed for replies.
Correct answer kglad

Thank You, it is clear now:)

in my fla file, my frameHandler calls a function mazeDisp.moveMazeWorld();    mazeDisp has a Class and in that class there is the function moveMazeWorld which calls another function from Box2D, it is world.step(0.016, 5, 5);

this last function takes time before starting to move things because its a huge function calculating a lot of b2body;

All I want is to make a "loadingScreen" visible while this function "world.step(0.016, 5, 5)" is progressing to start moving things and then Hide it when things are working fine.

But the issue is that as soon as this function is called, it stops everything else until it is done thinking. And I cannot hide/unhide, add/remove and move/stop anything.

Of course I understand without having the code it is hard for you to understand what is going on in here (The reason I wanted to communicate privately). But as I cannot copy paste the code in forum Please tell me what is the best thing to do if a function is too heavy and takes time to start working (in general) in the matter of telling the user to wait! I cannot use a Loading-Bar as there is nothing to load. And even if it was possible I don't know how to do it while the function stops things already.

P.s this function causes the delay ONLY the FIRST time it runs.


use a listener for your 'loading" screen (Event.ADDED_TO_STAGE) and call your world.step function from that listener function.

1 reply

kglad
Community Expert
Community Expert
January 21, 2015

comment out line 13.  does that ''loadingscreen' appear?

Inspiring
January 21, 2015

line 05 Kglad. Happy to see you again:)

Kglad I just realized something! Before, I was thinking as the mazeDisp.createMaze() at line 13 does a lot of work so the loadingScreen must be seen untill the function finished its job, BUT THEN i realized that function works fast enough as I cannot see the loadingScreen being visible at line 05 and then invisible at line 18.  My big problem is another function which will be called in my frameHandler in future which causes all the problem and delay and that function is from Box2D being: world.step(), I don't know if you've worked with Box2D.

Kglad do you check you messages sent in your website?

I'd like to communicate with you:)

kglad
Community Expert
Community Expert
January 21, 2015

i only offer free help in the adobe forums. i communicate via email if you want to hire me.