How to Create Maps and Keys? - actionscript-3

I'm trying to give names to some variables. But I'm getting error TypeError: Error #1010
var squareArr:Object = {
b1: {
piece: wn1_txt,
pieceLoc: {
x: "47",
y: "297"
}
},
c1: {
piece: wb1_txt,
pieceLoc: {
x: "97",
y: "297"
}
},
...
addChild(squareArr.b1.piece);
addChild(squareArr.c1.piece);
...
var i:int;
if ((mvB.charAt(mvB.length - 2) == "a") && (mvB.charAt(mvB.length - 1) == "1") || (mvB.charAt(mvB.length - 2) == "a") && (mvB.charAt(mvB.length - 1) == "3") || (mvB.charAt(mvB.length - 2) == "a") && (mvB.charAt(mvB.length - 1) == "5") || (mvB.charAt(mvB.length - 2) == "a") && (mvB.charAt(mvB.length - 1) == "7") || (mvB.charAt(mvB.length - 2) == "b") && (mvB.charAt(mvB.length - 1) == "2") || (mvB.charAt(mvB.length - 2) == "b") && (mvB.charAt(mvB.length - 1) == "4") || (mvB.charAt(mvB.length - 2) == "b") && (mvB.charAt(mvB.length - 1) == "6") || (mvB.charAt(mvB.length - 2) == "b") && (mvB.charAt(mvB.length - 1) == "8") || (mvB.charAt(mvB.length - 2) == "c") && (mvB.charAt(mvB.length - 1) == "1") || (mvB.charAt(mvB.length - 2) == "c") && (mvB.charAt(mvB.length - 1) == "3") || (mvB.charAt(mvB.length - 2) == "c") && (mvB.charAt(mvB.length - 1) == "5") || (mvB.charAt(mvB.length - 2) == "c") && (mvB.charAt(mvB.length - 1) == "7") || (mvB.charAt(mvB.length - 2) == "d") && (mvB.charAt(mvB.length - 1) == "2")
|| (mvB.charAt(mvB.length - 2) == "d") && (mvB.charAt(mvB.length - 1) == "4") || (mvB.charAt(mvB.length - 2) == "d") && (mvB.charAt(mvB.length - 1) == "6") || (mvB.charAt(mvB.length - 2) == "d") && (mvB.charAt(mvB.length - 1) == "8") || (mvB.charAt(mvB.length - 2) == "e") && (mvB.charAt(mvB.length - 1) == "1") || (mvB.charAt(mvB.length - 2) == "e") && (mvB.charAt(mvB.length - 1) == "3") || (mvB.charAt(mvB.length - 2) == "e") && (mvB.charAt(mvB.length - 1) == "5") || (mvB.charAt(mvB.length - 2) == "e") && (mvB.charAt(mvB.length - 1) == "7") || (mvB.charAt(mvB.length - 2) == "f") && (mvB.charAt(mvB.length - 1) == "2") || (mvB.charAt(mvB.length - 2) == "f") && (mvB.charAt(mvB.length - 1) == "4") || (mvB.charAt(mvB.length - 2) == "f") && (mvB.charAt(mvB.length - 1) == "6") || (mvB.charAt(mvB.length - 2) == "f") && (mvB.charAt(mvB.length - 1) == "8") || (mvB.charAt(mvB.length - 2) == "g") && (mvB.charAt(mvB.length - 1) == "1") || (mvB.charAt(mvB.length - 2) == "g") && (mvB.charAt(mvB.length - 1) == "3")
|| (mvB.charAt(mvB.length - 2) == "g") && (mvB.charAt(mvB.length - 1) == "5") || (mvB.charAt(mvB.length - 2) == "g") && (mvB.charAt(mvB.length - 1) == "7") || (mvB.charAt(mvB.length - 2) == "h") && (mvB.charAt(mvB.length - 1) == "2") || (mvB.charAt(mvB.length - 2) == "h") && (mvB.charAt(mvB.length - 1) == "4") || (mvB.charAt(mvB.length - 2) == "h") && (mvB.charAt(mvB.length - 1) == "6") || (mvB.charAt(mvB.length - 2) == "h") && (mvB.charAt(mvB.length - 1) == "8")) {
for(i=1; i<=8; i++) {
for( num=97; num<105; num++){
if (squareArr[String.fromCharCode(num) + i].piece == wb1_txt) {
oldSquare = String.fromCharCode(num) + i;
}
}
}
newSquare = mvB.charAt(mvB.length - 2) + mvB.charAt(mvB.length - 1);
currentPiece = Object(squareArr[oldSquare]).piece;
TweenLite.to(currentPiece, 0.3, {x:squareArr[newSquare].x, y:squareArr[newSquare].y, ease:Linear.easeNone, onComplete:isMovingFunction});
...

Check what items you access in squareArr, do they defined, etc.
For example, check your iteration logic:
var squareName:String;
for (i = 1; i <= 8; i++) {
for (num = 97; num < 105; num++) {
squareName = String.fromCharCode(num) + i;
if(squareName in squareArr){
if (squareArr[squareName].piece == wb1_txt) {
oldSquare = String.fromCharCode(num) + i;
}
}else{
trace("There is no " + squareName + " property");
}
}
}

Related

How to change the value of this.random_variable from html in component.ts Angular

Instead of having all the code from onblur in html I have to make a function in component.ts. But I have no ideea how to pass for example the this.type from html to component.ts such that when i change the value in component.ts it should change it's value in html as well.
<input id="date" type="text" #date
min="{{minDate|date:'yyyy-MM-dd'}}" max="{{maxDate|date:'yyyy-MM-dd'}}"
placeholder="Today"
onfocus="
this.type='date'
document.getElementById('date').addEventListener('keyup',function(e){
if (e.which == 13) {
this.blur();
}
});
"
onblur="
selected_date=this.value.split('-');
min_date=this.min.split('-');
max_date=this.max.split('-');
if( ( parseInt(selected_date[0], 10) > parseInt(min_date[0], 10) && parseInt(selected_date[0], 10) < parseInt(max_date[0], 10)) ||
( parseInt(selected_date[0], 10) == parseInt(max_date[0], 10) && parseInt(selected_date[1], 10) < parseInt(max_date[1], 10) ) ||
( parseInt(selected_date[0], 10) == parseInt(max_date[0], 10) && parseInt(selected_date[1], 10) == parseInt(max_date[1], 10) && parseInt(selected_date[2], 10) <= parseInt(max_date[2], 10)) ||
( parseInt(selected_date[0], 10) == parseInt(min_date[0], 10) && parseInt(selected_date[1], 10) > parseInt(min_date[1], 10) ) ||
( parseInt(selected_date[0], 10) == parseInt(min_date[0], 10) && parseInt(selected_date[1], 10) == parseInt(min_date[1], 10) && parseInt(selected_date[2], 10) >= parseInt(min_date[2], 10))
){
this.type='text';
this.value = selected_date[2].toString() + ' ' + selected_date[1].toString() + ' ' + selected_date[0].toString();
}
else{
if(selected_date == ''){
this.type='text';
}
else{
this.type='text';
error='Please enter a valid date';
this.value=error.toString();
}
}"
>
There are a few ways to do this.
One of the simplest is ngModel. Basically links a variable to a field.
<input [(ngModel)]="varName" (blur)="functionName(varName)">
In component you will have a funciton like this:
ngOnIt(){
varName = '';
}
functionName(string varName) {
//**do stuff**
//the varName inside brackets is not required as
//"this.varName" will already have the value
}

Data call using apend in controller

Hy. I'm learning about Laravel
im using append to enter data in select option
here is my append code
if($('.type').val()=="MAG") {
$('.tools').empty();
$('.tools').append('<?php echo $MAGRES ?>');
$(".tools").prop('disabled', false);
$('.level').empty();
$('.level').append('<?php echo $mlevel ?>');
$(".level").prop('disabled', false);
}
if($('.type').val()=="WAG") {
$('.tools').empty();
$('.tools').append('<?php echo $WAGRES ?>');
$(".tools").prop('disabled', false);
$('.level').empty();
$('.level').append('<?php echo $flevel ?>');
$(".level").prop('disabled', false);
}
Here is my controller
$openM =\App\eventcontroller::where('eventcontroller.eventID','=',$id)->where('type','MAG')->first();
$openF =\App\eventcontroller::where('eventcontroller.eventID','=',$id)->where('type','WAG')->first();
$mlevel='<option value="">-- Choose Levels --</option>';
$flevel='<option value="">-- Choose Levels --</option>';
if($openM->OneO == 1 || $openM->OneA == 1 || $openM->OneB == 1 || $openM->OneC == 1 || $openM->OneD == 1){$mlevel=$mlevel.'<option value="Level 1">Level {{$event->onename}} </option>';}
if($openM->TwoO == 1 || $openM->TwoA == 1 || $openM->TwoB == 1 || $openM->TwoC == 1 || $openM->TwoD == 1){$mlevel=$mlevel.'<option value="Level 2">Level {{$event->twoname}}</option>';}
if($openM->ThreeO == 1 || $openM->ThreeA == 1 || $openM->ThreeB == 1 || $openM->ThreeC == 1 || $openM->ThreeD == 1){$mlevel=$mlevel.'<option value="Level 3">Level {{$event->threename}}</option>';}
if($openM->FourO == 1 || $openM->FourA == 1 || $openM->FourB == 1 || $openM->FourC == 1 || $openM->FourD == 1){$mlevel=$mlevel.'<option value="Level 4">Level {{$event->fourname}}</option>';}
if($openM->FiveO == 1 || $openM->FiveA == 1 || $openM->FiveB == 1 || $openM->FiveC == 1 || $openM->FiveD == 1){$mlevel=$mlevel.'<option value="Level 5">Level {{$event->fivename}}</option>';}
if($openM->FigO == 1 || $openM->Fig1 == 1 ||$openM->Fig2 == 1){$mlevel=$mlevel.'<option value="FIG">FIG</option>';}
if($openF->OneO == 1 || $openF->OneA == 1 || $openF->OneB == 1 || $openF->OneC == 1 || $openF->OneD == 1){$flevel=$flevel.'<option value="Level 1">Level {{$event->onename}}</option>';}
if($openF->TwoO == 1 || $openF->TwoA == 1 || $openF->TwoB == 1 || $openF->TwoC == 1 || $openF->TwoD == 1){$flevel=$flevel.'<option value="Level 2">Level {{$event->twoname}}</option>';}
if($openF->ThreeO == 1 || $openF->ThreeA == 1 || $openF->ThreeB == 1 || $openF->ThreeC == 1 || $openF->ThreeD == 1){$flevel=$flevel.'<option value="Level 3">Level {{$event->threename}}</option>';}
if($openF->FourO == 1 || $openF->FourA == 1 || $openF->FourB == 1 || $openF->FourC == 1 || $openF->FourD == 1){$flevel=$flevel.'<option value="Level 4">Level {{$event->fourname}}</option>';}
if($openF->FiveO == 1 || $openF->FiveA == 1 || $openF->FiveB == 1 || $openF->FiveC == 1 || $openF->FiveD == 1){$flevel=$flevel.'<option value="Level 5">Level {{$event->fivename}}</option>';}
if($openF->FigO == 1 || $openF->Fig1 == 1 ||$openF->Fig2 == 1){$flevel=$flevel.'<option value="FIG">FIG</option>';}
there is no problem to display the options
but its print text :
'{{$event->onename}}' not data from $event->onename
i want it shows $event->onename data from database.
can anyone help me? thank you
Because you are using Blade syntax in your controller file, that is why it is displaying {{$event->onename}} instead of its actual value.
You can do like
if($openM->OneO == 1 || $openM->OneA == 1 || $openM->OneB == 1 || $openM->OneC == 1 || $openM->OneD == 1){
$mlevel= $mlevel."<option value=\"Level 1\">Level {$event->onename} </option>";
}
Or
if($openM->OneO == 1 || $openM->OneA == 1 || $openM->OneB == 1 || $openM->OneC == 1 || $openM->OneD == 1){
$mlevel = $mlevel.'<option value="Level 1">Level '.$event->onename.'</option>';
}

Shorten if Statement Actionscript 3

I just started learning actionscript and I'm wondering how could I shorten this if statement
if (txtInputTemp.charAt(track - 1) == "a" || txtInputTemp.charAt(track - 1) == "b" || txtInputTemp.charAt(track - 1) == "c" || txtInputTemp.charAt(track - 1) == "d" || txtInputTemp.charAt(track - 1) == "e" || txtInputTemp.charAt(track - 1) == "f" || txtInputTemp.charAt(track - 1) == "g" || txtInputTemp.charAt(track - 1) == "h" || txtInputTemp.charAt(track - 1) == "i" || txtInputTemp.charAt(track - 1) == "j" || txtInputTemp.charAt(track - 1) == "k" || txtInputTemp.charAt(track - 1) == "l" || txtInputTemp.charAt(track - 1) == "m" || txtInputTemp.charAt(track - 1) == "n" || txtInputTemp.charAt(track - 1) == "o" || txtInputTemp.charAt(track - 1) == "p" || txtInputTemp.charAt(track - 1) == "q" || txtInputTemp.charAt(track - 1) == "r" || txtInputTemp.charAt(track - 1) == "s" || txtInputTemp.charAt(track - 1) == "t" || txtInputTemp.charAt(track - 1) == "u" || txtInputTemp.charAt(track - 1) == "v" || txtInputTemp.charAt(track - 1) == "w" || txtInputTemp.charAt(track - 1) == "x" || txtInputTemp.charAt(track - 1) == "y" || txtInputTemp.charAt(track - 1) == "z" || txtInputTemp.charAt(track - 1) == "." || txtInputTemp.charAt(track - 1) == "'" || txtInputTemp.charAt(track - 1) == "-" || txtInputTemp.charAt(track - 1) == " ") { }
Any help is appreciated.
It can rewrite a-z to range specification.
somechar>="a" && somechar<="z"
But I have no idea how to shorten these symbols.
== "."
== "'"
== "-"
== " "
var somechar:String = txtInputTemp.charAt(track - 1);
if ((somechar>="a" && somechar<="z")||somechar == "."||somechar == "'"||somechar == "-"||somechar == " ")
{
// do something
}
Working Example: http://wonderfl.net/c/A9Hv
Option2: Use array.indexOf(char) == -1 or not.
var someArray: Array = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",".","'","-"," "];
var somechar:String = txtInputTemp.charAt(track - 1);
if (someArray.indexOf(somechar) != -1)
{
// Do something
}

(f) script works (e) doesnt

i have these two scripts that do the same thing just on different pages, but the f script works and the e script doesnt, any help??
function onEdit(e) {
if (e.source.getActiveSheet().getName() !== "RS3 Points" ||
e.range.columnStart < 9 || e.range.columnStart > 35 ||
e.range.rowStart < 4 || e.range
.columnStart < e.range.columnEnd) return;
e.range.offset(0, 37 - e.range.columnStart).setValue(new Date());
}
function onEdit(f) {
if (f.source.getActiveSheet().getName() !== "OS Points" ||
f.range.columnStart < 6 || f.range.columnStart > 37 ||
f.range.rowStart < 4 || f.range
.columnStart < f.range.columnEnd) return;
f.range.offset(0, 39 - f.range.columnStart).setValue(new Date());
}
Munkey's intuition is right. You can't have more than one onEdit() in the same project. Moreover 'e' is not a random letter (that can be replaced by any other letter) but stands for 'event object'. You can read more about that here. The solution would indeed consist in 'merging' the two scripts into one. Give this a try:
function onEdit(e) {
var ind = ["RS3 Points", "OS Points"].indexOf(e.source.getActiveSheet()
.getName()),
startCol = [9, 6],
endCol = [35, 37],
offset = [37, 39];
if (ind === -1 || e.range.columnStart < startCol[ind] || e.range.columnStart > endCol[ind] ||
e.range.rowStart < 4 || e.range.columnStart < e.range.columnEnd) return;
e.range.offset(0, offset[ind] - e.range.columnStart)
.setValue(new Date());
}
I don't think you can have 2 onEdits in google scripts.
If you comment out the f function, does the e one work?
cant you put them in one onedit function as a solution.
function onEdit(e) {
if (e.source.getActiveSheet().getName() !== "RS3 Points" ||
e.range.columnStart < 9 || e.range.columnStart > 35 ||
e.range.rowStart < 4 || e.range
.columnStart < e.range.columnEnd) return;
e.range.offset(0, 37 - e.range.columnStart).setValue(new Date());
if (e.source.getActiveSheet().getName() !== "OS Points" ||
e.range.columnStart < 6 || e.range.columnStart > 37 ||
e.range.rowStart < 4 || e.range
.columnStart < e.range.columnEnd) return;
e.range.offset(0, 39 - e.range.columnStart).setValue(new Date());
}
Something like that, but its untested.
I think If i'm reading your code correctly, you're looking for Not equals to sheet name, it might be better to change it to equals instead.

How to implement the AND command in a Google apps function correctly?

I have a function that checks if a cell in column 7 is checked.
if (r.getColumn() == 7 && r.getValue() == "x")
How do I write this to check if EITHER column 7 OR Column 8 are checked?
if (r.getColumn() == 7 && r.getValue() == "x") OR if (r.getColumn() == 8 && r.getValue() == "x")
doesn't seem to work.
OR is represented with ||
So if you want (7 OR 8) AND x , just write :
if ((r.getColumn() == 7 || r.getColumn() == 8) && r.getValue() == "x")