Be a Supporter!

Overriding functions?

  • 252 Views
  • 3 Replies
New Topic Respond to this Topic
Fatelogic
Fatelogic
  • Member since: May. 3, 2012
  • Offline.
Forum Stats
Member
Level 13
Artist
Overriding functions? 2012-12-18 21:08:01 Reply

Fate here once again, pals :D

Tonight's question: Is there a way for a function to "override" another function?

As always, allow me to explain:

I have one function that stops the scene at frame 1 in this way:

addEventListener(Event.ENTER_FRAME, habilitacionqf101);
function habilitacionqf101(event:Event)
{
if (OState01<=14){
stop();
}

else if (OState01>=15){
qf1.alpha = 1;
play();
this.removeEventListener(Event.ENTER_FRAME, habilitacionqf101);
}

else{
trace("review code")
}

}

Making long story short, this bit of code prevents the scene from playing until the variable "OState" (a numeric variable based on a second per second timer) reaches (or gets above) 15.

This is intended to prevent the player from being able to activate certain buttons until 15 seconds have passed.

However, I NEED to be able to use ANOTHER button at any time, even when the timer hasn't reached 15 seconds yet.

My newb skillz made me design that button like this:

chansetbutton.addEventListener(MouseEvent.CLICK, chanset01);

function chanset01 ( m:MouseEvent )
{
chanset1 = true;
play();
trace("Acknowledged")
}

This button has 3 objectives. The first one is to transform the "chanset1" variable value (a variable not needed to be explained here) from "false" to "true".

The third objective is to trace an "Acknowledged" message in order to check if it's working or not... and it is. It traces the message without problem... however, the "play();" command set to activate itself (which I intended for it to override the "habilitacionqf101" function previously explained) at the click of the mouse won't do squat. The game still forces me to wait until the 15 seconds passes before being able to use that button as it was intended.

Question is... is there any way to tell the "habilitacionqf101" function to be overriden if the "chansetbutton" is clicked? (aka: if I press that particular button, the game shouldn't force me to wait the stablished 15 seconds).

As you might be able to see, I'm no specialist over AS3 scripting... I'm an ilustrator, so this can get somewhat tricky for me... I deal with photoshop brushes, not functions, variables and such xD

Any ideas?

Fate out!

MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Overriding functions? 2012-12-18 21:33:56 Reply

You can actually use "override function habilitacionqf101(event:Event):void { }"

But only in a specific situation that you're not in, what you can do is within the function check "event.currentTarget.name" to see which button was pressed and do things in a certain situation. Either that you can have the button go to a different function that conditionally calls the other needed function.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
milchreis
milchreis
  • Member since: Jan. 11, 2008
  • Offline.
Forum Stats
Member
Level 26
Programmer
Response to Overriding functions? 2012-12-18 21:48:54 Reply

At 12/18/12 09:08 PM, Fatelogic wrote: Making long story short, this bit of code prevents the scene from playing until the variable "OState" (a numeric variable based on a second per second timer) reaches (or gets above) 15.

This is intended to prevent the player from being able to activate certain buttons until 15 seconds have passed.

Enable the buttons and whatever else you want to do upon the TimerEvent of the timer, don't do polling with the ENTER_FRAME.
It really is a poor approach.

Question is... is there any way to tell the "habilitacionqf101" function to be overriden if the "chansetbutton" is clicked? (aka: if I press that particular button, the game shouldn't force me to wait the stablished 15 seconds).

Notice the benefit of actually using Events "properly" instead:
Both MouseEvent and TimerEvent extend Event, you can register the listener (addEventListener) for both Events with the same handler function and and enable your buttons in it.

Fatelogic
Fatelogic
  • Member since: May. 3, 2012
  • Offline.
Forum Stats
Member
Level 13
Artist
Response to Overriding functions? 2012-12-19 00:38:19 Reply

Thanks for the support guys. I think I found my way around this issue. ^^