Nested script in action script 3 - actionscript-3

Okay someone could really help me with this I've been working REALLY hard to get this working up until this point. One last thing is I need is the nextquestion1 function to bring me to the last from of my application.
I click on my button nextQuestion_btn to take me to one of the labled frames I have. I click on it and nothing happens. Also there is a lot of missing code in between the two Event Listener's , just so you know.
So...How can I make this code so I can trigger the next frame with the button?
stage.addEventListener(Event.CHANGE, checkTotal1000)
function checkTotal1000(e:Event){
var tech:Number = parseInt(tech_txt.text);
var med:Number = parseInt(med_txt.text);
var space:Number = parseInt(space_txt.text);
var genetic:Number = parseInt(ge_txt.text);
var worldComp:Number = parseInt(worldComp_txt.text);
var mars:Number = parseInt(mars_txt.text);
var worldColab:Number = parseInt(worldColab_txt.text);
var nothing:Number = parseInt(nothing_txt.text);
var zombieApocFinal:Number = zombieApoc + genetic;
var robotApocFinal:Number = robotApoc+ tech;
var plagueFinal:Number = plague + med;
var asteroidFinal:Number = asteroid + mars;
var iceAgeFinal:Number = iceAge + nothing;
var aliensFinal:Number = aliens + space;
var nukeWarFinal:Number = nukeWar + worldComp;
//var happyEverAfterFinal:Number = ;
trace(aliensFinal);
var total1000:Number = tech + med + space +
worldComp + mars + genetic + worldColab + nothing;
nextQuestion_btn.addEventListener(MouseEvent.MOUSE_DOWN, nextQuestion1)
function nextQuestion1(e:MouseEvent){
if(tech && med && space && genetic && worldComp
&& mars && worldColab && nothing == 125){
gotoAndStop(7);
}
if(robotApocFinal > zombieApocFinal && plagueFinal &&
asteroidFinal && iceAgeFinal && aliensFinal &&
nukeWarFinal){
gotoAndStop("Robot");
}
else if(zombieApocFinal > robotApocFinal && plagueFinal &&
asteroidFinal && iceAgeFinal && aliensFinal &&
nukeWarFinal){
gotoAndStop("Zombie");
}
else if( plagueFinal > zombieApocFinal && robotApocFinal &&
asteroidFinal && iceAgeFinal && aliensFinal &&
nukeWarFinal){
gotoAndStop("Plague");
}
else if( asteroidFinal > zombieApocFinal && robotApocFinal &&
plagueFinal && iceAgeFinal && aliensFinal &&
nukeWarFinal){
gotoAndStop("Asteroid");
}
else if( iceAgeFinal > zombieApocFinal && robotApocFinal &&
plagueFinal && asteroidFinal && aliensFinal &&
nukeWarFinal){
gotoAndStop("IceAge");
}
else if( aliensFinal > zombieApocFinal && robotApocFinal &&
plagueFinal && asteroidFinal && iceAgeFinal &&
nukeWarFinal){
gotoAndStop("Aliens");
}
else if( nukeWarFinal > zombieApocFinal && robotApocFinal &&
plagueFinal && asteroidFinal && iceAgeFinal &&
aliensFinal){
gotoAndStop("Nuke");
}
}
}

Apparently you are using binary flags, but you use && operator which only works with booleans. This way if either of your ints is 0, no condition is satisfied. You apparently want to trigger the gotoAndStop() if one of the ints is greater than others. For this you can use the following code:
var bestFinal:int=Math.max(asteroidFinal, zombieApocFinal, robotApocFinal,
plagueFinal, iceAgeFinal, aliensFinal, nukeWarFinal);
if (bestFinal==asteroidFinal) {...}
else if (bestFinal==zombieApocFinal) {...}
...
If you are about to test if one var is greater than all the others, you cannot use what you've written, instead you use either Math.max() and check for equality, or you write many comparations and unite them via &&, like this:
if ((asteroidFinal > zombieApocFinal) && (asteroidFinal > robotApocFinal) &&
(asteroidFinal > plagueFinal) && (asteroidFinal > iceAgeFinal) &&
(asteroidFinal > aliensFinal) && (asteroidFinal > nukeWarFinal))

Related

PrimeFaces Extension Sheet Restrict Decimal Places For Input

I want to restrict decimal places up to 1. User shouldnt type multiple dots(1..99) and (1.99). I want 1.9 2.6 for ex. Not 2.66 then convert into 2.7 etc. I have to use pe:sheetcolumn. I tried to add p:inputnumber and other p: components than pe extension. But pe:sheetcolumn have to be. With below approach it just let user to type multiple dots and multiple decimal places. It just convert to 1 decimal after user entered value on screen with #0.0. But i want to restrict on input to type multiple decimal places than 1 and multiple dots. I thought about javascript keyup event but i think it would be bad approach. How can i achive that
<pe:sheetcolumn headerText="SOME" value="#{SOME.some}" colWidth="200"
colType="numeric" numericPattern="#0.0" >
</pe:sheetcolumn>
For example for p:inputNumber as you can see on image user cant type multiple dots and they cant add decimal places more than 6.
Example
I want to do same thing with pe:sheetColumn. How can i do that
My JSF VERSION : 2.2.1 PRÄ°MEFACES AND PRIMEFACES EXTENSION VERSION : 6.2
If you install this MonkeyPatch you can then tweak the output to do whatever your want. I am pretty sure you can get the current cell with var currentValue = this.getDataAtCell(row , col) If you add this JS to your app you can then tweak how it handles keypresses and validation.
I added this line for you
var currentValue = this.getDataAtCell(row , col); // VALUE HERE!
So you can validate whatever your want with your code and if there is already a "." don't accept another "." etc.
if (PrimeFaces.widget.ExtSheet) {
PrimeFaces.widget.ExtSheet.prototype.handleHotBeforeKeyDown = function(e) {
var selectedLast = this.getSelectedLast();
if (!selectedLast) {
return;
}
var row = selectedLast[0];
var col = selectedLast[1];
var celltype = this.getCellMeta(row, col).type;
var currentValue = this.getDataAtCell(row , col); // VALUE HERE!
var evt = e || window.event; // IE support
var key = evt.charCode || evt.keyCode || 0;
var shiftDown = e.shiftKey;
// #740 tab on last cell should focus this next component
if (this.allowTabOffSheet && key == 9) {
var lastRow = this.countRows() - 1;
var lastCol = this.countCols() - 1;
if ((!shiftDown && row === lastRow && col === lastCol) ||
(shiftDown && row === 0 && col === 0)) {
e.stopImmediatePropagation();
this.unlisten();
this.deselectCell();
//add all elements we want to include in our selection
var focusableElements = 'a:not([disabled]), button:not([disabled]), input[type=text]:not([disabled]):not([hidden]):not([aria-hidden="true"]), [tabindex]:not([disabled]):not([tabindex="-1"]):not([aria-hidden="true"])';
if (document.activeElement && document.activeElement.form) {
var focusable = Array.prototype.filter.call(document.activeElement.form.querySelectorAll(focusableElements),
function(element) {
//check for visibility while always include the current activeElement
return element.offsetWidth > 0 || element.offsetHeight > 0 || element === document.activeElement
});
var index = focusable.indexOf(document.activeElement);
if (index > -1) {
var nextElement = focusable[index + 1] || focusable[0];
nextElement.focus();
}
}
}
return;
}
// prevent Alpha chars in numeric sheet cells
if (celltype === "numeric") {
// #766 do not block if just CTRL or SHIFT key
if (key === 16 || key === 17) {
return;
}
// #739 allow navigation
var ctrlDown = evt.ctrlKey || evt.metaKey; // Mac support
if (shiftDown || ctrlDown) {
// navigation keys
if (key == 9 || (key >= 35 && key <= 40)) {
return;
}
}
// check for cut and paste
var isClipboard = false;
// Check for Alt+Gr (http://en.wikipedia.org/wiki/AltGr_key)
if (ctrlDown && evt.altKey) isClipboard = false;
// Check for ctrl+c, v and x
else if (ctrlDown && key == 65) isClipboard = true; // a (select all)
else if (ctrlDown && key == 67) isClipboard = true; // c
else if (ctrlDown && key == 86) isClipboard = true; // v
else if (ctrlDown && key == 88) isClipboard = true; // x
// allow backspace, tab, delete, enter, arrows, numbers and keypad numbers
// ONLY home, end, F5, F12, minus (-), period (.)
// console.log('Key: ' + key + ' Shift: ' + e.shiftKey + ' Clipboard: ' + isClipboard);
var isNumeric = ((key == 8) || (key == 9) || (key == 13) ||
(key == 46) || (key == 110) || (key == 116) ||
(key == 123) || (key == 188) || (key == 189) ||
(key == 190) || ((key >= 35) && (key <= 40)) ||
((key >= 48) && (key <= 57)) || ((key >= 96) && (key <= 105)));
if ((!isNumeric && !isClipboard) || shiftDown) {
// prevent alpha characters
e.stopImmediatePropagation();
e.preventDefault();
}
}
}
}

Encountering an error while attempting to create a game

I'm trying to create a crossword puzzle game using Actionscript 3.0 in Adobe
Animate. For the game coding, I followed an online tutorial and now I'm encountering an error. The error occurs whenever I'm in the actual game scene, no errors are encountered on the home page or instruction page. can anyone help me? my coding skills are below basic.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at CROSSWORD_CODE_fla::MainTimeline/entFrame().
stop();
quitbtn.addEventListener(MouseEvent.CLICK, quitt);
function quitt(evt: MouseEvent): void {
gotoAndStop("start");
}
var hippopotamus: Number = 0;
var horse: Number = 0;
var eel: Number = 0;
var frog: Number = 0;
var ant: Number = 0;
var turtle: Number = 0;
var tiger: Number = 0;
var bird: Number = 0;
var penguin: Number = 0;
var orca: Number = 0;
var octopus: Number = 0;
var owl: Number = 0;
var snail: Number = 0;
var duck: Number = 0;
var kangaroo: Number = 0;
var iguana: Number = 0;
var ALLwords:Number = 0;
var Total:Number = 0;
{
stage.addEventListener(Event.ENTER_FRAME, entFrame);
function entFrame(evt:Event):void {
if ((hypoH.text == ("h").toString())
&& (hypo1.text == ("i").toString())
&& (hypoP.text == ("p").toString())
&& (hypoP2.text == ("p").toString())
&& (hypoO.text == ("o").toString())
&& (hypoP3.text == ("p").toString())
&& (hypoO2.text == ("o").toString())
&& (hypoT.text == ("t").toString())
&& (hypoA.text == ("a").toString())
&& (hypoM.text == ("m").toString())
&& (hypoU.text == ("u").toString())
&& (hypoS.text == ("s").toString()))
{
hippopotamus = 1;
trace("hippopotamus");
}
}
{
if ((hrsO.text == ("o").toString())
&& (hrsR.text == ("r").toString())
&& (hrsS.text == ("s").toString())
&& (hrsE.text == ("e").toString()))
{
horse = 1;
trace("horse");
}
}
{
if ((eelE.text == ("e").toString())
&& (eel1.text == ("l").toString()))
{
eel = 1;
trace("eel");
}
}
{
if ((penP.text == ("p").toString())
&& (penE.text == ("e").toString())
&& (penN.text == ("n").toString())
&& (penG.text == ("g").toString())
&& (penU.text == ("u").toString())
&& (pen1.text == ("i").toString())
&& (penN2.text == ("n").toString()))
{
penguin = 1;
trace("penguin");
}
}
{
if ((brdB.text == ("b").toString())
&& (brdR.text == ("r").toString())
&& (brdD.text == ("d").toString()))
{
bird = 1;
trace("bird");
}
}
{
if ((octO.text == ("o").toString())
&& (octC.text == ("c").toString())
&& (octT.text == ("t").toString())
&& (octO2.text == ("0").toString())
&& (octP.text == ("p").toString())
&& (octU.text == ("u").toString()))
{
octopus = 1;
trace("octopus");
}
}
{
if ((orcR.text == ("r").toString())
&& (orcC.text == ("c").toString())
&& (orcA.text == ("a").toString()))
{
orca = 1;
trace("orca");
}
}
{
if ((owlO.text == ("o").toString())
&& (owlW.text == ("w").toString()))
{
owl = 1;
trace("owl");
}
}
{
if ((nailS.text == ("s").toString())
&& (nailA.text == ("a").toString())
&& (nail1.text == ("i").toString())
&& (nailL.text == ("l").toString()))
{
snail = 1;
trace("snail");
}
}
{
if ((dkD.text == ("d").toString())
&& (dkU.text == ("u").toString())
&& (dkC.text == ("c").toString())
&& (dkK.text == ("k").toString()))
{
duck = 1;
trace("duck");
}
}
{
if ((groA.text == ("a").toString())
&& (groN.text == ("n").toString())
&& (groG.text == ("g").toString())
&& (groA2.text == ("a").toString())
&& (groR.text == ("r").toString())
&& (groO.text == ("o").toString()))
{
kangaroo = 1;
trace("kangaroo");
}
}
{
if ((frgF.text == ("f").toString())
&& (frgR.text == ("r").toString())
&& (frgG.text == ("g").toString()))
{
frog = 1;
trace("frog");
}
}
{
if ((ignG.text == ("g").toString())
&& (ignU.text == ("u").toString())
&& (ignA.text == ("a").toString())
&& (ignN.text == ("n").toString()))
{
iguana = 1;
trace("iguana");
}
}
{
if ((antA.text == ("a").toString())
&& (antN.text == ("n").toString()))
{
ant = 1;
trace("ant");
}
}
{
if ((trtT.text == ("t").toString())
&& (trtU.text == ("u").toString())
&& (trtR.text == ("r").toString())
&& (trtT2.text == ("t").toString())
&& (trtL.text == ("l").toString()))
{
turtle = 1;
trace("turtle");
}
}
{
if ((tgr1.text == ("i").toString())
&& (tgrG.text == ("g").toString())
&& (tgrE.text == ("e").toString()))
{
tiger = 1;
trace("tiger");
}
}
ALLwords = hippopotamus + horse + eel + frog + tiger + octopus + penguin + bird + orca +
turtle + duck + snail + ant + kangaroo + iguana + owl;
Total = 16 - ALLwords;
if (Total == 0)
{
trace("Gameover");
}
incorrectTXT.text = ("you have" + Total+ " incorrect words remaining").toString();
}

DataTables age range filter is not working

I got a problem when filtering the age range in DataTables. I am using DataTables ver 1.10.10. I am confused because when I started to build the code it was working properly, but when I tested again, it's not working anymore.
I hope anyone could tell me where I am missing since it is a very noob question.
Here is my javascript
$.fn.dataTable.ext.search.push(
function (settings, data, dataIndex) {
var from = parseInt( $('#ageFrom').val(), 10 );
var to = parseInt( $('#ageTo').val(), 10);
var age = parseFloat( data[3] ) || 0;
if ( (isNaN(from) && isNaN(to)) ||
(isNaN(from) && age <= to) ||
(from <= age && isNaN(to)) ||
(from <= age && age <= to) )
{
return true;
}
return false;
}
);
$('#ageFrom, #ageTo').on('change keyup', function() {
if ($('#ageFrom').val() == "" || $('#ageTo').val() == "") {
table.draw()
}
else {
table.draw();
}
});
Thanks in advance!
Cheers

How can I make the generated numbers never to be the same?

I'm a beginner in programming and I have been trying to make my 3 random generated numbers and the answer never to be the same, but no matter how I tried I didn't get the result that I wanted. I would be very thankful if someone would put me on the right path :)
This is a piece of code for the first randomly generated number, the other two are exactly the same.
//Random number 1
{
btnAns1.label = "" + random1;
if(mathOperationL1 == 1)
{
random1 = Math.floor(Math.random()* 24) + 1;
do
{
random1 = Math.floor(Math.random()* 24) + 1;
}
while((random1 > 24) && (random1 === answerL1) && (random1 === random2) && (random1 === random3));
btnAns1.label = "" + random1;
}
else if (mathOperationL1 == 2)
{
random1 = Math.floor(Math.random()* 11) + 1;
do
{
random1 = Math.floor(Math.random()* 11) + 1;
}
while((random1 > 11) && (random1 === answerL1) && (random1 === random2) && (random1 === random3));
btnAns1.label = "" + random1;
}
else if (mathOperationL1 == 3)
{
random1 = Math.floor(Math.random()* 144) + 1;
do
{
random1 = Math.floor(Math.random()* 144) + 1;
}
while((random1 > 144) && (random1 === answerL1) && (random1 === random2) && (random1 === random3));
btnAns1.label = "" + random1;
}
else if (mathOperationL1 == 4)
{
random1 = Math.floor(Math.random()* 12) + 1;
do
{
random1 = Math.floor(Math.random()* 12) + 1;
}
while((random1 > 12) && (random1 === answerL1) && (random1 === random2) && (random1 === random3));
btnAns1.label = "" + random1;
}
}
There are no errors in the code and everything else is working perfectly.It is just the line of code that is supposed to make the numbers never to be the same just doesn't work and after running the code for few times I eventually get numbers that are the same. while((random1 > 24) && (random1 === answerL1) && (random1 === random2) && (random1 === random3));
Thanks for your help in advance! :)
Your condition while((random1 > 24)... is always false because you generate numbers like 1 to 24 and they NEVER exceed 24.
Lets do it algorithmically.
var aList:Array = new Array;
// Put the user's input here. Don't forget that
// TextField.text contains String value rather than int.
aList[0] = 5;
// Each line adds a random element different from
// the elements that are already in the Array.
aList[1] = smartRandom(1, 10, aList);
aList[2] = smartRandom(4, 15, aList);
aList[3] = smartRandom(9, 20, aList);
// Let's see what we get this time.
trace(aList);
// Generates a random int from "min" to "max" inclusive,
// while avoiding all the numbers from the "avoid" Array.
// Note that it doesn't actually checks if it is possible
// to do so, thus smartRandom(1, 1, [1]) will result in the
// infinite loop because conditions will never be satisfied.
function smartRandom(min:int, max:int, avoid:Array):int
{
var result:int;
do
{
result = min + Math.random() * (max - min + 1);
}
// The Array.indexOf(...) method returns -1 if the argument
// is not on the given Array or it returns a 0-based
// index of the element that is equal to the given argument.
while (avoid.indexOf(result) > -1);
return result;
}
while((random1 > 24) || (random1 === answerL1) || (random1 === random2) || (random1 === random3));
The && operator insists that all the tests are true if it is to run again. The || is the logical OR, so any combination tested will cause the loop to run again.
Edit: I should also say, there seems to be alot of duplicated effort in this code.. perhaps once you are comfortable with your operator's behaviour you will be able to simplify the flow.

as3 - Changing position checking for in IF statement

I am trying to catch X.Y positions with an IF statement, and IF the coordinates are true I want it to go on to the next set of coordinates. In the code below I attempted my best but I keep getting the "Cannot assign to a non-reference value." Error.
public function onDd(event:TimerEvent):void
{
if (this.rootClass.world.strMapName == "test" && a1.x = a1.x = 327.1 && a1.y = 249.65)
{
a1.x = 360.7;
a1.y = 204.25;
}
else if (a1.x = 410.15 && a1.y = 204.25)
{
a1.x = 360.7;
a1.y = 204.25;
}
}
You have used a wrong comparison operator
If you want to compare two values you must use == or ===
So your code will become:
public function onDd(event:TimerEvent):void {
if (this.rootClass.world.strMapName == "test" && a1.x == 327.1 && a1.y == 249.65) {
a1.x = 360.7;
a1.y = 204.25;
}
else if (a1.x == 410.15 && a1.y == 204.25) {
a1.x = 360.7;
a1.y = 204.25;
}
}