3in1 quick questions (stage.focus; && logic; importing classes)

Subscribe to 3in1 quick questions (stage.focus; && logic; importing classes) 6 posts

avatar for AMD_Paulius_J AMD_Paulius_J 110 posts
Flag Post

Just a few small questions, just to make sure.

1. I see that after pressing a button and going to the next frame, stage gets no focus, do i need to manually insert

stage.focus = stage
in a next frame? Or is there something i’m doing wrong with buttons, because if i make MovieClip as a button everything is fine.

2. Let’s say we need to move background only if all three players are on the right side, this line should do it, but it doesn’t do exactly what we want:


(loop)
if (player1.x && player2.x && player3.x > 400)
{
back.x -= 5;
}

It will start moving background if player2.x and player3.x is > 400 but it doesn’t care about player1.x, so i had to change it to this:

(loop)
if (player1.x > 400 && player2.x && player3.x > 400)
{
back.x -= 5;
}

So, can’t we have more than 2 logic statements?

3. Is there somewhere a list of all classes like:

import fl.motion.MotionEvent;
import flash.utils.Timer;

Because when creating an .as file flash does not import them automatically for some reason:(

How do you know which one to import?

 
avatar for skyboy skyboy 6261 posts
Flag Post
  1. buttons are weird; manually set the focus to stage to work around inconsistent behaviour.
  2. you need to check for > 400 on each value: x1 > 400 && x2 > 400 && x3 > 400 just doing x1 && x2 && x3 > 400 says to the computer “if x1 is not 0 and if x2 is not 0 and x3 is greater than 400…”
  3. any proper IDE will provide you a list and automatically import as much as it can (or give you an option between two of the same name in different places) such as FlashDevelop; as for a list: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/package-detail.html
    • knowing what classes to import comes down to knowing what you want to do; it’s your job to know what you want to do and how to do it, not the computer’s. the computer is just a tool; it can neither read your mind nor think for itself. it does only what you instruct it to do.
 
avatar for BigJM BigJM 468 posts
Flag Post

2) player1.x && player2.x && player3.x > 400 evaluates player1.x and player2.x as booleans. As long as these two values are not 0 or NaN and player3.x is greater than 400, the statement will return true.

3) You import whatever you need to use.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/index.html

beaten…

 
avatar for AMD_Paulius_J AMD_Paulius_J 110 posts
Flag Post

Very good answers, that cleared things out, thank you.

 
avatar for DrYoshiyahu DrYoshiyahu 678 posts
Flag Post

When it comes to importing, I just create the code I need and if I forgot to import something, an error will pop up telling me so, so I just import stuff as I go.

 
avatar for feartehstickman feartehstickman 521 posts
Flag Post

Just to clear this up, stage.focus = stage is the proper way of getting my KeyboardEvent Listeners to work, if I set them to stage?