as3 boolean variable won't pass out of function - actionscript-3

For some reason my value is not being updated outside of the function. I'm trying to make a button, instanced "plus", move a movie clip "topArrow" constantly upward. I figured the boolean would be an easy way to trigger this, but it isn't being updated outside of the function. Why is this?
import flash.events.Event;
import flash.events.MouseEvent;
var speed:Number = 1;
plus.addEventListener(MouseEvent.MOUSE_DOWN, arrow_up);
plus.addEventListener(MouseEvent.MOUSE_UP, arrow_stop);
minus.addEventListener(MouseEvent.MOUSE_DOWN, arrow_down);
minus.addEventListener(MouseEvent.MOUSE_UP, arrow_stop);
var move_up:Boolean = false;
var move_down:Boolean = false;
function arrow_up(event:MouseEvent):void
{
trace("button pressed");
move_up = true;
}
function arrow_stop(event:MouseEvent):void
{
move_up = false;
move_down = false;
}
function arrow_down(event:MouseEvent):void
{
move_down = true;
}
while (move_up==true)
{
topArrow.y += speed;
}
while (move_down==true)
{
topArrow.y -= speed;
}
if(move_up)
{
trace("true");
}

Those while loops are scary, once move_up is true it will go into that loop and never exit?
I would do something like the below instead to animate the movie clip :
var speed:Number = 1;
plus.addEventListener(MouseEvent.MOUSE_DOWN, arrow_up);
plus.addEventListener(MouseEvent.MOUSE_UP, arrow_stop);
minus.addEventListener(MouseEvent.MOUSE_DOWN, arrow_down);
minus.addEventListener(MouseEvent.MOUSE_UP, arrow_stop);
stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
var move_up:Boolean = false;
var move_down:Boolean = false;
function arrow_up(event:MouseEvent):void
{
trace("button pressed");
move_up = true;
}
function arrow_stop(event:MouseEvent):void
{
move_up = false;
move_down = false;
}
function arrow_down(event:MouseEvent):void
{
move_down = true;
}
function onEnterFrame(event:Event):void
{
if(move_up)
topArrow.y += speed;
else if(move_down)
topArrow.y -=speed;
if(move_up)
{
trace("true");
}
}

Decompile binary and take a look at move_up setter function.

Related

Sprite movement basically right but

This is basically just drag and double click to set (so drag is temporarily disabled) but the sprite doesn't keep with the mouse- can someone point me to better code- otherwise I'll with go with this- so much more to do.
//The initial event performed when the button is first clicked;
internal var m_nDoubleClickSpeed:Number = 300;
internal var m_toMouse:Number;
internal var moveready:Boolean = false;
internal var initalx:uint;
internal var initialy:uint;
internal var move:Boolean;
internal function clickDoubleClick(e:MouseEvent):void {
if (isSet == false) {
this.startDrag();
}
if (isNaN(m_toMouse)==false) {
clearTimeout(m_toMouse);
HandleDoubleClick();
} else {
m_toMouse = setTimeout(HandleSingleClick, m_nDoubleClickSpeed);
}
}
internal function HandleSingleClick():void {
trace("HandleSingleClick");
trace("isSet");
trace(isSet);
this.stopDrag();
m_toMouse = NaN;
}
internal function HandleDoubleClick():void {
if (isSet == false) {
isSet = true;
this.stopDrag()
} else {
isSet = false;
}
trace("HandleDoubleClick");
m_toMouse = NaN;
}
internal function goodX(inX:Number):Number {
if (inX < 0) {
return 0;
}
if (inX > (stage.stageWidth) ) {
return (stage.stageWidth);
}
return inX;
}
internal function goodY(inY:Number):Number {
if (inY < 0) {
return 0;
}
if (inY > stage.stageHeight) {
return stage.stageHeight;
}
return inY;
}
I'm not sure if I understood you correctly. So you want to start drag on single click and drag until doubleclicked right? If so you can try something like that:
public class ClickAndDrag extends Sprite
{
private var clickTimeout:uint;
private var doubleClickSpeed:int = 500;
private var clickedOnce:Boolean;
private var mouseOnClick:Point;
private var isDragging:Boolean;
public function ClickAndDrag()
{
graphics.beginFill(Math.random()*0xffffff, 1);
graphics.drawCircle(0, 0, 20);
graphics.endFill();
this.buttonMode = true;
addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown);
}
private function handleMouseDown(e:MouseEvent):void
{
if (isDragging)
{
if (clickedOnce)
handleDoubleClicked();
else
{
//if it's not clicket within next doubleClickSpeed ms then doubleClickSpeed will be set to false;
clickedOnce = true;
clickTimeout = setTimeout( handleClickTimeout, doubleClickSpeed );
}
}
else
{
handleClickAndDrag();
}
}
//clicked once when dragging
private function handleClickOnce():void
{
graphics.clear();
graphics.beginFill(Math.random()*0xffffff, 1);
graphics.drawCircle(0, 0, 20);
graphics.endFill();
}
//clicked once when not dragging
private function handleClickAndDrag():void
{
isDragging = true;
this.addEventListener(Event.ENTER_FRAME, handleFrame);
mouseOnClick = new Point(this.mouseX, this.mouseY);
}
//doubleclicked when dragging
private function handleDoubleClicked():void
{
clearTimeout(clickTimeout);
clickedOnce = false;
this.removeEventListener(Event.ENTER_FRAME, handleFrame);
isDragging = false;
}
private function handleClickTimeout():void
{
clickedOnce = false;
handleClickOnce();
}
private function handleFrame(e:Event):void
{
this.x = stage.mouseX - mouseOnClick.x;
this.y = stage.mouseY - mouseOnClick.y;
}
}
It basically waits for mousedown and if it's already dragging it checks if you clicked once (changes color) ot twice (stops dragging). Or if it's not dragging yet then it starts dragging. You may also want to handle leaving the stage (Event.MOUSE_LEAVE).

AS3 error 1061 trying to get collision

" Player.as, Line 59 1061: Call to a possibly undefined method hitTestObject through a reference with static type Class."
I am new to flash and am trying to make a game, specifically I am trying to make it so the player class in a game can collide with things, I am using a square at the bottom of his feet (not yet referenced in the code) and a MovieClip called collisionTest
package
{
import flash.display.Stage;
import flash.display.MovieClip;
import flash.events.Event;
import KeyObject;
public class Player extends MovieClip
{
public var stageRef:Stage;
public var key:KeyObject;
//add these four variables:
public var leftPressed:Boolean = false; //keeps track of whether the left arrow key is pressed
public var rightPressed:Boolean = false; //same, but for right key pressed
public var upPressed:Boolean = false; //...up key pressed
public var downPressed:Boolean = false; //...down key pressed
private var gravity:Number = 2;
private var runSpeed:Number = 5;
private var touchingGround:Boolean = false;
public var vPressed:Boolean = false;
public function Player(stageRef:Stage, X:int, Y:int):void
{
this.stageRef = stageRef;
this.x = X;
this.y = Y;
key = new KeyObject(stageRef);
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
public function loop(e:Event):void
{
checkKeypresses(); //call "checkKeypresses()" every frame
checkCollisions();
if(leftPressed)
{
x -= runSpeed;
}else if(rightPressed)
{
x += runSpeed;
}
if(upPressed)
{
y -= runSpeed;
}else if(downPressed)
{
y += runSpeed;
}
}
public function checkCollisions():void
{
**(this is line 59)** if(Player.hitTestObject(Player.collisionTest)){
touchingGround = true;
trace("gounded");
}
}
public function checkKeypresses():void
{
// I used http://www.dakmm.com/?p=272 as a reference to get the keyCode numbers for each key
if(key.isDown(37) || key.isDown(65)){ // if left arrow or A is pressed
leftPressed = true;
//trace("left pressed");
} else {
leftPressed = false;
}
if(key.isDown(38) || key.isDown(87)){ // if up arrow or W is pressed
upPressed = true;
//trace("up pressed");
} else {
upPressed = false;
}
if(key.isDown(39) || key.isDown(68)){ //if right arrow or D is pressed
rightPressed = true;
//trace("right pressed");
} else {
rightPressed = false;
}
if(key.isDown(40) || key.isDown(83)){ //if down arrow or S is pressed
downPressed = true;
//trace("down pressed");
} else {
downPressed = false;
}
}
}
}
Function hitTestObject isn't a static function, so you should call it from an object instance, same to the collisionTest.
So it should be
this.hitTestObject(collisionTest);//set collisionTest in the Player class

How to make a movie clip visible if only five movie clips (not more) are clicked

I have 25 movie clips on stage and they all can be clicked and colored. I want a movie clip named text_mc to became visible if only 5 specific buttons from those are clicked and colored - not more. If the user choose more than those five movie clips (even thought that 5 movie clips are included) then the movie clip named text_mc should stay invisible. I can' t do the last part: if more than those 5 specific movie clips are clicked then the text_mc should stay invisible. Can you please help me? This is my code
stop();
import flash.display.MovieClip;
var sximata:MovieClip = square1;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.geom.ColorTransform;
text_mc.visible=false;
square1.addEventListener(MouseEvent.CLICK, onsquare1);
function onsquare1(e:MouseEvent):void {
sximata = square1;
}
square2.addEventListener(MouseEvent.CLICK, onsquare2);
function onsquare2(e:MouseEvent):void {
sximata = square2;
}
square3.addEventListener(MouseEvent.CLICK, onsquare3);
function onsquare3(e:MouseEvent):void {
sximata = square3;
}
square4.addEventListener(MouseEvent.CLICK, onsquare4);
function onsquare4(e:MouseEvent):void {
sximata = square4;
}
square5.addEventListener(MouseEvent.CLICK, onsquare5);
function onsquare5(e:MouseEvent):void {
sximata = square5;
}
square6.addEventListener(MouseEvent.CLICK, onsquare6);
function onsquare6(e:MouseEvent):void {
sximata = square6;
}
square7.addEventListener(MouseEvent.CLICK, onsquare7);
function onsquare7(e:MouseEvent):void {
sximata = square7;
}
square8.addEventListener(MouseEvent.CLICK, onsquare8);
function onsquare8(e:MouseEvent):void {
sximata = square8;
square8Clicked = true;
checkButtons();
}
square9.addEventListener(MouseEvent.CLICK, onsquare9);
function onsquare9(e:MouseEvent):void {
sximata = square9;
square9Clicked = true;
checkButtons();
}
square10.addEventListener(MouseEvent.CLICK, onsquare10);
function onsquare10(e:MouseEvent):void {
sximata = square10;
square10Clicked = true;
checkButtons();
}
square11.addEventListener(MouseEvent.CLICK, onsquare11);
function onsquare11(e:MouseEvent):void {
sximata = square11;
}
square12.addEventListener(MouseEvent.CLICK, onsquare12);
function onsquare12(e:MouseEvent):void {
sximata = square12;
}
square13.addEventListener(MouseEvent.CLICK, onsquare13);
function onsquare13(e:MouseEvent):void {
sximata = square13;
square13Clicked = true;
checkButtons();
}
square14.addEventListener(MouseEvent.CLICK, onsquare14);
function onsquare14(e:MouseEvent):void {
sximata = square14;
square14Clicked = true;
checkButtons();
}
square15.addEventListener(MouseEvent.CLICK, onsquare15);
function onsquare15(e:MouseEvent):void {
sximata = square15;
}
square16.addEventListener(MouseEvent.CLICK, onsquare16);
function onsquare16(e:MouseEvent):void {
sximata = square16;
}
square17.addEventListener(MouseEvent.CLICK, onsquare17);
function onsquare17(e:MouseEvent):void {
sximata = square17;
}
square18.addEventListener(MouseEvent.CLICK, onsquare18);
function onsquare18(e:MouseEvent):void {
sximata = square18;
}
square19.addEventListener(MouseEvent.CLICK, onsquare19);
function onsquare19(e:MouseEvent):void {
sximata = square19;
}
square20.addEventListener(MouseEvent.CLICK, onsquare20);
function onsquare20(e:MouseEvent):void {
sximata = square20;
}
square21.addEventListener(MouseEvent.CLICK, onsquare21);
function onsquare21(e:MouseEvent):void {
sximata = square21;
}
square22.addEventListener(MouseEvent.CLICK, onsquare22);
function onsquare22(e:MouseEvent):void {
sximata = square22;
}
square23.addEventListener(MouseEvent.CLICK, onsquare23);
function onsquare23(e:MouseEvent):void {
sximata = square23;
}
square24.addEventListener(MouseEvent.CLICK, onsquare24);
function onsquare24(e:MouseEvent):void {
sximata = square24;
}
square25.addEventListener(MouseEvent.CLICK, onsquare25);
function onsquare25(e:MouseEvent):void {
sximata = square25;
}
var myColorTransform:ColorTransform=transform.colorTransform;
red_btn.addEventListener(MouseEvent.CLICK, changeColour);
function changeColour(event:MouseEvent):void {
myColorTransform.color=0xBD8D46;
sximata.transform.colorTransform=myColorTransform;
}
resetButton.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{
gotoAndPlay(1);
}
var square8Clicked:Boolean = false;
var square9Clicked:Boolean = false;
var square10Clicked:Boolean = false;
var square13Clicked:Boolean = false;
var square14Clicked:Boolean = false;
function checkButtons():void
{
if(square8Clicked && square9Clicked && square10Clicked && square13Clicked && square14Clicked)
{
text_mc.visible = true;
}
}
You could add a boolean variable to each of the other functions that turns to true if any of the other squares are clicked. For example:
var isClicked:Boolean = false;
square1.addEventListener(MouseEvent.CLICK, onsquare1);
function onsquare1(e:MouseEvent):void {
sximata = square1;
isClicked = true;
}
And then in your check buttons function, check to see if "isClicked" is still false:
function checkButtons():void
{
if(!isClicked && square8Clicked && square9Clicked && square10Clicked && square13Clicked && square14Clicked)
{
text_mc.visible = true;
}
}
My solution is below. It's based on counting the number of clicks received by each type of MovieClip the user can click on.The relevant parts of the code would be in the onClick() and checkClickCounts() methods.
First, you'll see that in the buildMCs() method I simply create a bunch of MovieClips and place them on the stage in a grid. I've made it so that the "specific" MCs that you mention are the first items on each row of the grid. To each of these "specific" MCs, I've added a property: isSpecial:Boolean and set it to true. Later, when a MC is clicked, the OnClick() method will check to see if the MC was special or not, and will increment the relevant click count property. Then, checkClickCounts() is called. If 5 good clicks and 0 bad clicks are counted up, then we let the user know. This is where you'd display your textfield. (In my case, I just draw a big red rectangle on the screen.
Another suggestion I demo here is to avoid repeating your mouse click code. If you look in the constructor, you'll see that I used this line:
this.addEventListener(MouseEvent.CLICK, onClick);
This tells the main stage sprite to listen to all mouse clicks, even the ones that happen to MovieClips inside of it. In the onClick() method I check to see if the item clicked - the target of the event - was a MovieClip. If it was, then I do the additional checking to see if the MC clicked was one that I wanted. By doing this, I was able to write the code for handling the mouse clicks once, and now if I need to change something, I only have to do it one time, rather than 25 times. Saves me time, but also makes the code less error-prone because I'm less likely to miss something if there's a change that needs to be made.
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;
public class Clicky extends Sprite
{
public function Clicky()
{
this.buildMCs();
this.addEventListener(MouseEvent.CLICK, onClick);
}
private function buildMCs ():void
{
var rows:int = 5;
var cols:int = 5;
var boxSize:int = 10;
for (var r:int = 0; r < rows; r++)
{
for (var c:int = 0; c < cols; c++)
{
var newMC:MovieClip = new MovieClip();
newMC.graphics.lineStyle(0, 0x00ff00);
// want to mark the "specific" movieclips
if (c == 0)
{
newMC.graphics.beginFill(0x0000ff);
// just something that makes this MC unique... ideally
// this would be not a MovieClip, but a class that defines
// actual properties worth checking for
newMC.isSpecial = true;
}
else
{
newMC.graphics.beginFill(0x00ff00);
}
newMC.graphics.drawRect(0, 0, boxSize, boxSize);
this.addChild(newMC);
newMC.x = (c * boxSize);
newMC.y = (r * boxSize);
}
}
}
private function onClick (e:MouseEvent):void
{
if (e.target is MovieClip)
{
var mc:MovieClip = e.target as MovieClip;
mc.alpha = .25;
// disable the clicking for the clicked item
mc.mouseEnabled = false;
if (mc.isSpecial)
{
_specialClicks++;
}
else
{
_badClicks++;
}
this.checkClickCounts();
}
}
private var _specialClicks:int = 0;
private var _badClicks:int = 0;
private function checkClickCounts ():void
{
if (_specialClicks == 5 && _badClicks == 0)
{
// do your thing - show the text_mc, play a sound, award a prize, etc.
this.graphics.beginFill(0xff0000);
this.graphics.drawRect(0, 0, 1000, 1000);
}
}
}
}

Actionscript 3 Making the character to Jump

I am making a platformer game. But I am having issue because whenever I pressed the spacebar to jump, the character will stuck in the mid-air. However, I can resolved the problem by holding spacebar and the character will land.
The issue is at mainJump() located inside Boy class.
I seen many people solved the problem by using action timeline, but my main problem is, are there anyway I can solve the problem by using an external class?
Main class
package
{
import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.utils.Timer;
import flash.text.*;
public class experimentingMain extends MovieClip
{
var count:Number = 0;
var myTimer:Timer = new Timer(10,count);
var classBoy:Boy;
//var activateGravity:gravity = new gravity();
var leftKey, rightKey, spaceKey, stopAnimation:Boolean;
public function experimentingMain()
{
myTimer.addEventListener(TimerEvent.TIMER, scoreUp);
myTimer.start();
classBoy = new Boy();
addChild(classBoy);
stage.addEventListener(KeyboardEvent.KEY_DOWN, pressTheDamnKey);
stage.addEventListener(KeyboardEvent.KEY_UP, liftTheDamnKey);
}
public function pressTheDamnKey(event:KeyboardEvent):void
{
if (event.keyCode == 37)
{
leftKey = true;
stopAnimation = false;
}
if (event.keyCode == 39)
{
rightKey = true;
stopAnimation = false;
}
if (event.keyCode == 32)
{
spaceKey = true;
stopAnimation = true;
}
}
public function liftTheDamnKey(event:KeyboardEvent):void
{
if (event.keyCode == 37)
{
leftKey = false;
stopAnimation = true;
}
if (event.keyCode == 39)
{
rightKey = false;
stopAnimation = true;
}
if (event.keyCode == 32)
{
spaceKey = false;
stopAnimation = true;
}
}
public function scoreUp(event:TimerEvent):void
{
scoreSystem.text = String("Score : "+myTimer.currentCount);
}
}
}
Boy class
package
{
import flash.display.*;
import flash.events.*;
public class Boy extends MovieClip
{
var leftKeyDown:Boolean = false;
var upKeyDown:Boolean = false;
var rightKeyDown:Boolean = false;
var downKeyDown:Boolean = false;
//the main character's speed
var mainSpeed:Number = 5;
//whether or not the main guy is jumping
var mainJumping:Boolean = false;
//how quickly should the jump start off
var jumpSpeedLimit:int = 40;
//the current speed of the jump;
var jumpSpeed:Number = 0;
var theCharacter:MovieClip;
var currentX,currentY:int;
public function Boy()
{
this.x = 600;
this.y = 540;
addEventListener(Event.ENTER_FRAME, boyMove);
}
public function boyMove(event:Event):void
{
currentX = this.x;
currentY = this.y;
if (MovieClip(parent).leftKey)
{
currentX += mainSpeed;
MovieClip(this).scaleX = 1;
}
if (MovieClip(parent).rightKey)
{
currentX -= mainSpeed;
MovieClip(this).scaleX = -1;
}
if (MovieClip(parent).spaceKey)
{
mainJump();
}
this.x = currentX;
this.y = currentY;
}
public function mainJump():void
{
currentY = this.y;
if (! mainJumping)
{
mainJumping = true;
jumpSpeed = jumpSpeedLimit * -1;
currentY += jumpSpeed;
}
else
{
if (jumpSpeed < 0)
{
jumpSpeed *= 1 - jumpSpeedLimit / 250;
if (jumpSpeed > -jumpSpeedLimit/12)
{
jumpSpeed *= -2;
}
}
}
if (jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit)
{
jumpSpeed *= 1 + jumpSpeedLimit / 120;
}
currentY += jumpSpeed;
if (currentY >= stage.stageHeight - MovieClip(this).height)
{
mainJumping = false;
currentY = stage.stageHeight - MovieClip(this).height;
}
}
}
}
First of all, formalize your code, eliminating sassy things like 'pressTheDamnKey,' which doesn't even describe the function very well because a function cannot press a key. That is an event handler and should be named either keyDownHandler or onKeyDown, nothing else.
Secondly, you rarely want to do any actual work in event handlers beyond the immediate concerns of the event data. Instead call out to the function which does the actual work. A handler handles the event, then calls the code which does the work. This separates out concerns nicely for when you want something else to be able to also make the little boy animate besides the enterFrameHandler, like perhaps a mouse.
I can imagine your trace log is getting filled up pretty quickly with "Score" lines since your timer is firing 100 times a second (10 milliseconds per). I would change that to not fire on a timer, but to be refreshed when the score actually changes.
The problem with the jumping, aside from spaghetti code, is that you are basing his movements upon whether the key is pressed or not by saving the state of the key press in a variable and having him continually inspect it. This is bad for a couple of reasons: 1. he should not need to reach out to his environment for information, it should be given to him by whatever object owns him or by objects that are responsible for telling him and 2. It requires you to continually hold down the spacebar or he will stop moving, since he checks to see if it is being held down (see problem 1).
I will address all these issues below, leaving out the scoring, which is another matter altogether.
package
{
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.utils.*;
// Sprite is preferred if you are not using the timeline
public class Application extends Sprite
{
private var boy:Boy;
public function Application()
{
boy = new Boy();
addChild(boy);
boy.x = 600; // set these here, not in the boy
boy.y = 540;
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler );
}
public function keyDownHandler(event:KeyboardEvent):void
{
switch(event.keyCode)
{
case 32: boy.jump();
break;
case 37: boy.moveLeft();
break;
case 39: boy.moveRight();
break;
default:
// ignored
break;
}
}
public function keyUpHandler(event:KeyboardEvent):void
{
switch(event.keyCode)
{
// ignored for jumping (32)
case 37: // fall through
case 39: boy.stop();
break;
default:
// ignored
break;
}
}
}//class
}//package
package
{
import flash.display.*;
import flash.events.*;
// It is assumed that there is an asset in the library
// that is typed to a Boy, thus it will be loaded onto
// the stage by the owner
public class Boy extends Sprite
{
private var horzSpeed :Number = 0;
private var vertSpeed :Number = 0;
private var floorHeight :Number;
private var jumpHeight :Number;
private var amJumping :Boolean = false;
public function Boy()
{
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
public function moveLeft():void
{
horzSpeed = -1;
}
public function moveRight():void
{
horzSpeed = 1;
}
public function stop():void
{
horzSpeed = 0;
}
public function jump():void
{
if (amJumping) return;
floorHeight = y;
jumpHeight = floorHeight + 20;
vertSpeed = 2;
amJumping = true;
animateJump();
}
private function enterFrameHandler(event:Event):void
{
animate();
}
private function animate():void
{
x += horzSpeed;
if( amJumping )
{
animateJump();
}
}
// Doing a simple version for this example.
// If you want an easier task of jumping with gravity,
// I recommend you employ Greensock's superb
// TweenLite tweening library.
private function animateJump():void
{
y += vertSpeed;
if( y >= jumpHeight )
{
y = jumpHeight;
vertSpeed = -2;
}
else if( y <= floorHeight )
{
y = floorHeight;
amJumping = false;
}
}
}//class
}//package
Another way to approach this, and probably the better way long-term, is for the boy to not even be responsible for moving himself. Instead, you would handle that in the parent, his owner or some special Animator class that is responsible for animating things on schedule. In this even more encapsulated paradigm, the boy is only responsible for updating his own internal look based upon the outside world telling him what is happening to him. He would no longer handle jumping internally, but instead would be responsible for doing things like animating things he owns, like his arms and legs.
You've got a mainJumping variable that is only true while the jump is running. Why not just use that?
if (MovieClip(parent).spaceKey || mainJumping)
{
mainJump();
}

to create quiz using StartDrag and stopDrag

Actually i have a quiz.fla. In the file ,two of them fill inthe blank questions and others are
multiple questions.
square1_mc must run only once not twice. İf user correct selected, doesnt run it again.
However,if mybadscoretext is 1 not increase 2,3,4. :S
how i can do all?
stop();
var myScore:Number = 0;
var myBadScore:Number=0;
square1_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag);
stage.addEventListener(MouseEvent.MOUSE_UP, drop);
function drag(e:MouseEvent):void
{
e.target.startDrag();
}
function drop(e:MouseEvent):void
{
square1_mc.stopDrag();
if (square1_mc.hitTestObject(square2_mc)== true)
{
square1_mc.x=129;
square1_mc.y=133;
this.graphics.clear();
this.graphics.lineStyle(2, 000000);
this.graphics.moveTo(square1_mc.x, square1_mc.y);
this.graphics.lineTo(square2_mc.x, square2_mc.y);
this.graphics.endFill();
myScore += 1;
score_txt.text=String(myScore);
square1_mc.removeEventListener(MouseEvent.MOUSE_DOWN, drag);
}
else
{
square1_mc.x=129;
square1_mc.y=133;
myBadScore += 1;
mybadscore_txt.text=String(myBadScore);
}
}
Add a variable to keep track of whether the bad score has been added:
var badMarked:Boolean = false;
function drag(e:MouseEvent):void
{
e.target.startDrag();
badMarked = false;
}
[...]
function drop(e:MouseEvent):void
{
if (square1_mc.hitTestObject(square2_mc)== true)
{
[...]
}
else if ( !badMarked )
{
square1_mc.x=129;
square1_mc.y=133;
myBadScore += 1;
mybadscore_txt.text=String(myBadScore);
badMarked = true;
}
}