as3 - Changing position checking for in IF statement - actionscript-3

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;
}
}

Related

AngularJS Selects Empty Option Even Valid Option is Avaliable

I'm using AngularJS ver. 1.2.15 on my project. And, I have a select element on one of my views as per below:
<select class="select-white form-control form-select" id="cat2_{{feed.id}}" ng-model="feed.operationstatusid" ng-change="updateCategoryAndStatus(feed, true)"></select>
And, I'm feeding this element like this:
function SetCategory2(cat1Id, feed) {
var feedId = feed.id;
var fromRuleOpStatusId = -1;
$('#cat2_' + feedId).find('option').remove();
if (cat1Id > -1) {
$('#cat2_' + feedId).append($('<option></option>').text(lang.SelectSubCategory).val(0));
$.each($scope.category2, function (index, cat2Item) {
$('#cat2_' + feedId).append($('<option></option>').text(cat2Item.statusdescription).val(cat2Item.id));
});
var isselected = false;
$.each($scope.category2, function (index, cat2Item) {
if (feed.operationstatusid == cat2Item.id) {
$('#cat2_' + feedId).val(cat2Item.id);
fromRuleOpStatusId = -1;
isselected = true;
}
else {
var feedStr = "";
if (feed.title != undefined && feed.title != null) {
feedStr = feed.title.toLowerCase();
}
if ($scope.catTitleRulesTwo) {
$.each($scope.catTitleRulesTwo, function (r_index, r_item) {
if (cat2Item.id == r_item.titleCode && !isselected) {
if (feedStr != undefined && feedStr != null && r_item != undefined && r_item != null) {
String.prototype.contains = function (str) { return this.toLowerCase().indexOf(str) !== -1; };
var text = feedStr;
if (eval(r_item.ruleexpression)) {
$('#cat2_' + feedId).val(cat2Item.id);
fromRuleOpStatusId = cat2Item.id;
isselected = true;
}
}
}
});
}
}
});
if (fromRuleOpStatusId != -1) {
feed.operationstatusid = fromRuleOpStatusId;
}
}
else {
$('#cat2_' + feedId).append($('<option></option>').text(lang.SelectSubCategory).val(0));
}
}
I am aware of the facts about eval function, but the project I'm working on is quite old, so does the code. Anyway, this is about business logic and quite irrelevant with the thing I'm going to ask (or so I was thinking).
As you can see I'm appending all the options before I set the value of the selectbox with using .val(...). I have also checked that values do match along with the data types. But, when I observe this function step by step, I saw that selected value does show up without flaw. After the code finish with my above mentioned function (SetCategory2), code goes through on of the function located on AngularJS file, named xhr.onreadystatechange. It's not a long function, so I'm sharing it also on below.
xhr.onreadystatechange = function() {
if (xhr && xhr.readyState == 4) {
var responseHeaders = null,
response = null;
if(status !== ABORTED) {
responseHeaders = xhr.getAllResponseHeaders();
response = ('response' in xhr) ? xhr.response : xhr.responseText;
}
completeRequest(callback,
status || xhr.status,
response,
responseHeaders);
}
};
After the code released from this function, respective selectbox's value is pointed at the empty option.
I have run into topics which talks about this behaviour might due to invalid option-value match, but as I described above, I append all my options before deciding the value. So, I can't figure out what I'm missing.
Thank you in advance.

How to ignore filtering for fields that are empty/undefined using filterPredicate

I am trying to understand the filterPredicate of MatTableDataSource, and when I thought I was close, I am missing some logic.
I want to filter through a datasource and if the array's value is blank or "", then it shouldn't filter for every value that is defined as "". In other words, filter with what it does know and not what it doesn't know.
I tried to assign the values to null if the length of the array is equal to 0. But even that did not work.
Typescript
this.registeredUserService.GetAllAdverts().subscribe(val => {
this.dataSource = new MatTableDataSource<Card>(val);
this.dataSource.paginator = this.paginator;
this.dataSource.filterPredicate = (myObject: IFilter, filterString: any) => {
let filterObj: IFilter = JSON.parse(filterString);
if (!filterObj.provinceName.includes(myObject.provinceName) ||
!filterObj.vehicleMake.includes(myObject.vehicleMake) ||
!filterObj.vehicleModel.includes(myObject.vehicleModel) ||
!filterObj.vehicleYear.includes(myObject.vehicleYear) ||
!filterObj.vehicleColor.includes(myObject.vehicleColor))
{
return false;
}
else {
return true;
}
}
filter()//whenever triggered, it should do the filtering
{
this.myFilter.provinceName = this.search.value.provinceSelector;
this.myFilter.vehicleMake = this.search.value.makeSelector;
this.myFilter.vehicleModel = this.search.value.modelSelector;
this.myFilter.vehicleColor = this.search.value.colorSelector;
this.myFilter.vehicleYear = this.search.value.yearSelector;
if (this.myFilter.provinceName.length == 0 &&
this.myFilter.vehicleMake.length == 0 &&
this.myFilter.vehicleModel.length == 0 &&
this.myFilter.vehicleColor.length == 0 &&
this.myFilter.vehicleYear.length == 0) {
this.dataSource.filter = '';
}
else {
this.dataSource.filter = JSON.stringify(this.myFilter);
}
}
myFilter: IFilter = {
provinceName: [],
vehicleMake: [],
vehicleModel: [],
vehicleColor: [],
vehicleYear: []
}
interface IFilter{
provinceName:any[],
vehicleMake:any[],
vehicleModel:any[],
vehicleColor:any[],
vehicleYear:any[]
}
What it should do: Filter based on my query
What it does: Only does filtering as soon as all the values are filled.
You just have to check the filter attribute before if it exists and length is greater 0 and when then search for it in your object.
this.registeredUserService.GetAllAdverts().subscribe(val => {
this.dataSource = new MatTableDataSource<Card>(val);
this.dataSource.paginator = this.paginator;
this.dataSource.filterPredicate = (myObject: IFilter, filterString: any) => {
let filterObj: IFilter = JSON.parse(filterString);
if (
(filterObj.provinceName && filterObj.provinceName.length > 0 && !filterObj.provinceName.includes(myObject.provinceName)) ||
(filterObj.vehicleMake && filterObj.vehicleMake.length > 0 && !filterObj.vehicleMake.includes(myObject.vehicleMake)) ||
(filterObj.vehicleModel && filterObj.vehicleModel.length > 0 && !filterObj.vehicleModel.includes(myObject.vehicleModel)) ||
(filterObj.vehicleYear && filterObj.vehicleYear.length > 0 && !filterObj.vehicleYear.includes(myObject.vehicleYear)) ||
(filterObj.vehicleColor && filterObj.vehicleColor.length > 0 && !filterObj.vehicleColor.includes(myObject.vehicleColor))
) {
return false;
} else {
return true;
}
}
});

Is there a way in Postman to change xml2Json conversion rules?

I have some instances where I need to convert my XML response, and in multiple cases I have nodes that appear once or more times.
If it looks like this bbb will be just another element:
<aaa>
<bbb>ccc</bbb>
</aaa>
and to get ccc value I have to access json like this: pm.response.json().aaa.bbb
But if XML looks something like this bbb will become array:
<aaa>
<bbb>ccc</bbb>
<bbb>ddd</bbb>
</aaa>
and to get ccc value I have to access json like this: pm.response.json().aaa.bbb[0]
Later on, when I use JSON data I need to always check whether I have one or multiple elements returned from provider. What I want is to avoid checking Array.isArray... all the time and force it to be array. Is there is such option?
I have created this group of functions, I hope they can help you (I think that transformIntoSingleElement is what you are looking for):
function stackTrace() {
var err = new Error();
console.log(err.stack);
return err;
}
function transformIntoArray(element, mandatory){
mandatory = (mandatory!==undefined)?mandatory:true;
if(element === undefined && mandatory){
stackTrace();
return element;
}
if(element === undefined)
return [];
if(element.constructor.name != "Array")
return [element];
return element;
}
function transformIntoSingleElement(element, index, mandatory){
mandatory = (mandatory!==undefined)?mandatory:true;
if(element === undefined && mandatory){
stackTrace();
return element;
}
if(element === undefined){
return element;
}
if(element.constructor.name == "Array"){
if(element.length >= index)
return element[index];
return element[0];
}
return element;
}
function getElementValue(element, dflt, mandatory){
dflt = dflt || "";
mandatory = (mandatory!==undefined)?mandatory:true;
if(element === undefined && mandatory){
stackTrace();
return element;
}
if(element === undefined)
return dflt;
if(element._ === undefined)
return element;
return element._;
}
function getAttributeValue(element, attribute, dflt, mandatory){
dflt = dflt || "";
mandatory = (mandatory!==undefined)?mandatory:true;
if(element === undefined && mandatory){
stackTrace();
return element;
}
if(element.$ !== undefined && element.$[attribute] !== undefined && (element.$[attribute] !== "" || (element.$[attribute] === "" && mandatory))){
return element.$[attribute];
}
return dflt;
}

checking if textfield is empty with multiline doesn''t work as3

this is my code:
stop();
var inputText:String;
var inputText2:String;
var inputText3:String;
var inputText4:String;
var inputText5:String;
var inputText6:String;
var inputText7:String;
var inputText8:String;
go.addEventListener(MouseEvent.CLICK, playBtnClickk);
function playBtnClickk(e:MouseEvent):void {
inputText = inputTXT.text;
inputText2 = inputTXT2.text;
inputText3 = inputTXT3.text;
inputText4 = inputTXT4.text;
inputText5 = inputTXT5.text;
inputText6 = inputTXT6.text;
inputText7 = inputTXT7.text;
inputText8 = inputTXT8.text;
if (
inputText2 !== "",
inputText3 !== "",
inputText4 !== "",
inputText5 !== "",
inputText6 !== "",
inputText7 !== "",
inputText8 !== "")
{ this.setChildIndex(allevelden, this.numChildren - 1); }
else{
gotoAndPlay(2);
}}
I one field isn't filled in, this.setChildIndex(allevelden, this.numChildren - 1); has to shop up, and if everything is filled in it has to go to frame 2.
all the textfields are input textfields and multilines but it doesn't work can someone help me please!!
I might be wrong but I never saw this syntax of separaring the condition on the if statement with a comma, you should separate your condintions with a double pipe for or, also your check is incorrect, try this:
if (
inputText == "" ||
inputText2 == "" ||
inputText3 == "" ||
inputText4 == "" ||
inputText5 == "" ||
inputText6 == "" ||
inputText7 == "" ||
inputText8 == "")
{ this.setChildIndex(allevelden, this.numChildren - 1); }
else{
gotoAndPlay(2);
}}
This reads: If any of your fields is empty then...

does gmaps support callback option

i want to get the cities list around a place defined with latitude and longitude
here is the simple code i use:
JSON.stringify = JSON.stringify || function (obj) {
var t = typeof (obj);
alert(t);
if (t != "object" || obj === null) {
if (t == "string") obj = '"'+obj+'"';
return String(obj);
} else {
var n, v, json = [], arr = (obj && obj.constructor == Array);
for (n in obj) {
v = obj[n]; t = typeof(v);
if (t == "string") v = '"'+v+'"';
else if (t == "object" && v !== null) v = JSON.stringify(v);
json.push((arr ? "" : '"' + n + '":') + String(v));
}
return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");
}
}
function insertReply(content) {
var JSONString = JSON.stringify(content);
document.body.innerHTML += JSONString;
alert(JSONString);
}
var script = document.createElement('script');
var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false&callback=insertReply";
script.src = (url);
document.body.appendChild(script);
but it seems that google maps doesnt support the callback option (...&callback=insertReply)
is the a solution for that?
thank you in advance..
It's not supported.
Use the gecoding-service of the Maps-Javascript-API instead.