Target instance object by using a variable value in Actionscript 3 - actionscript-3

I have a series of objects each with instance names such as:
object1
object2
object3
going up in numerical order. I want to access each one depending on the value of a variable. For example
myVar:Num = 2;
I would like to use this value to select the appropriate object. In javascript or JQuery would be written like this:
object + myVar
Which would return me object2. However, this approach is obviously not working in AS3. Can anybody help me put please?

Related

Convert 2 Dimensional Array into Object

I'm hoping for some help converting a 2D array into an object.
In my spreadsheet I have a table of names and Google Drive folder identifiers (these are just examples, not real identifiers haha) -
Name
Identifier
Name1
27uXqJux5ub4xlSOJpDgozuSBXpzdaqMbz
Name2
VDe67puraYNFyPNCptBkffuQcajjJLFzE
Using getvalues(), I have created an array of these cells called folderIds (leaving out the header row).
I then have another array which contains just the names, called names.
[Name1, Name2, Name3, etc]
My intention is to run a loop which uses the names in the second array to retrieve the folder identifier in the first array, but I'm stuck on how to convert folderIds into an object so that I can use the names array as a key to retrieve the folder identifier. The solution needs to be dynamic as folderIds will grow (and possibly change) over time, so I can't just manually define the object.
Ideally I would have an object that looks like this -
const folderIdsObj = {
"Name1" : "27uXqJux5ub4xlSOJpDgozuSBXpzdaqMbz",
"Name2" : "VDe67puraYNFyPNCptBkffuQcajjJLFzE"
etc
}
And I would use folderIdsObj[names[i]] in a loop to retrieve the relevant folder identifier.
I've been digging around all over the internet, and it looks like the solution might be to use the map method, but I've never used map before and I'm not really sure where to start. I had a go but couldn't figure out how to map folderIds[0][0] to folderIds[0][1] (for example).
There may be a much simpler solution that I've missed too, though I've tried various array methods with no success.
Thanks in advance!
you can achieve this by implementing this code...
twoDArray = [["Name1","12ee1du912nc1"], ["Name2", "1231cqnisani83"]]
const obj = Object.fromEntries(twoDArray.map(([k, v]) => [k, v]));
console.log(obj);
more information here

Azure | ADF | How to use a String variable to lookup a Key in an Object type Parameter and retrieve its Value

I am using Azure Data Factory. I'm trying to use a String variable to lookup a Key in a JSON array and retrieve its Value. I can't seem to figure out how to do this in ADF.
Details:
I have defined a Pipeline Parameter named "obj", type "Object" and content:
{"values":{"key1":"value1","key2":"value2"}}
Parameter definition
I need to use this pipeline to find a value named "key1" and return it as "value1"; "key2" and return it as "value2"... and so on. I'm planning to use my "obj" as a dictionary, to accomplish this.
Technically speaking, If i want to find the value for key2, I can use the code below, and it will be returned "value2":
#pipeline().parameters.obj.values.key2
What i can't figure out is how to do it using a variable (instead of hardcoded "key2").
To clear things out: I have a for-loop and, inside it, i have just a copy activity: for-each contents
The purpose of the copy activity is to copy the file named item().name, but save it in ADLS as whatever item().name translates to, according to "obj"
This is how the for-loop could be built, using Python: python-for-loop
In ADF, I tried a lot of things (using concat, replace...), but none worked. The simpliest woult be this:
#pipeline().parameters.obj.values.item().name
but it throws the following error:
{"code":"BadRequest","message":"ErrorCode=InvalidTemplate, ErrorMessage=Unable to parse expression 'pipeline().parameters.obj.values.item().name'","target":"pipeline/name_of_the_pipeline/runid/run_id","details":null,"error":null}
So, can you please give any ideas how to define my expression?
I feel this must be really obvious, but I'm not getting there.....
Thanks.
Hello fellow Pythonista!
The solution in ADF is actually to reference just as you would in Python by enclosing the 'variable' in square brackets.
I created a pipeline with a parameter obj like yours
and, as a demo, the pipeline has a single Set Variable activity that got the value for key2 into a variable.
This is documented but you need X-ray vision to spot it here.
Based on your comments, this is the output of a Filter activity. The Filter activity's output is an object that contains an array named value, so you need to iterate over the "output.value":
Inside the ForEach you reference the name of the item using "item().name":
EDIT BASED ON MORE INFORMATION:
The task is to now take the #item().name value and use it as a dynamic property name against a JSON array. This is a bit of a challenge given the limited nature of the Pipeline Expression Language (PEL). Array elements in PEL can only be referenced by their index value, so to do this kind of complex lookup you will need to loop over the array and do some string parsing. Since you are already inside a FOR loop, and nested FOR loops are not supported, you will need to execute another pipeline to handle this process AND the Copy activity. Warning: this gets ugly, but works.
Child Pipeline
Define a pipeline with two parameters, one for the values array and one for the item().name:
When you execute the child pipeline, pass #pipeline.parameters.obj.values as "valuesArray" and #item().name as "keyValue".
You will need several string parsing operations, so create some string variables in the Pipeline:
In the Child Pipeline, add a ForEach activity. Check the Sequential box and set the Items to the valuesArray parameter:
Inside the ForEach, start by cleaning up the current item and storing it as a variable to make it a little easier to consume.
Parse the object key out of the variable [this is where it starts to get a little ugly]:
Add an IF condition to test the value of the current key to the keyValue parameter:
Add an activity to the TRUE condition that parses the value into a variable [gets really ugly here]:
Meanwhile, back at the Pipeline
At this point, after the ForEach, you will have a variable (IterationValue) that contains the correct value from your original array:
Now that you have this value, you can use that variable as a DataSet parameter in the Copy activity.

Parsing query string in Node to allow logical operators

I would like something similar to what node-odata offers, but I do not want to wrap it around my database (I am using Cassandra and already have an Express app set up with routes, etc).
Currently, I grab data from the database (which will ultimately return a JSON object to the user) and then using the values passed in the query string I modify the results with JavaScript and pass the modified JSON object on through to the user.
I cannot pass in a query string like this http://localhost:3001/getSomeData?name=jim&age=21||eyeColor=red which includes logical operators in the query string, and would grab all data and filter it where the name is "jim", the age is "21" OR eyeColor is "red". So this would give me all Jims that have either eyeColor red and/or age of 21. If I used this age=21&&eyeColor=red I would expect to get all Jims that have BOTH eye color of red and are 21 years old.
I was thinking of using a custom query string that can be passed in (i.e. inclusive=age&inclusive=eyeColor appended at the end of the query string) and in Node, I would modify the filter results to treat these properties (age and eyeColor) as if they were passed in with the || OR operator). However, this is quite verbose, and I was hoping there was a library or another simpler implementation out there that solves this problem, or somehow lets me pass in simple logical operators into the query string.
I ended up using this library to achieve what I wanted: https://www.npmjs.com/package/jspath
It's well document and worked perfectly for my situation.
npm i querystringify //or
https://cdnjs.cloudflare.com/ajax/libs/qs/6.7.0/qs.min.js
//it will will return an object
const myObject = Qs.parse(location.search, {ignoreQueryPrefix: true});
//you can use object destructuring.
const {age,eyeColor}=Qs.parse(location.search, {ignoreQueryPrefix: true})
By default, parsing will include "?" too.
{ignoreQueryPrefix: true} this option will omit "?".

Which one to use Value vs std::string in cocos2d-x V3 C++?

According to http://www.cocos2d-x.org/wiki/Value,
Value can handle strings as well as int, float, bool, etc.
I'm confused when I have to make a choice between using
std::string
or
Value
In what circumstances should I use Value over std::string, and vice versa??
I think you have misunderstood the Value object. As written in the documentation you linked to:
cocos2d::Value is a wrapper class for many primitives ([...] and std::string) plus [...]
So really Value is an object that wraps a bunch of other types of variables, which allows cocos2d-x to have loosely-typed structures like the ValueMap (a hash of strings to Values - where each Value can be a different type of object) and ValueVector (a list of Values).
For example, if you wanted to have a configuration hash with keys that are all strings, but with a bunch of different values - in vanilla C++, you would have to create a separate data structure for each type of value you want to save, but with Value you can just do:
unordered_map<std::string, cocos2d::Value> configuration;
configuration["numEnemies"] = Value(10);
configuration["gameTitle"] = Value("Super Mega Raiders");
It's just a mechanism to create some loose typing in C++ which is a strongly-typed language.
You can save a string in a Value with something like this:
std::string name = "Vidur";
Value nameVal = Value(name);
And then later retrieve it with:
std::string retrievedName = nameVal.asString();
If you attempt to parse a Value as the wrong type, it will throw an error in runtime, since this is isn't something that the compiler can figure out.
Do let me know if you have any questions.

Flash Builder how do I get data from the fields of the first row of datagrid

Flash Builder:
How do I get data from the fields of the first row of datagrid spark?
I want to print them on the screen.
I'm starting in Flash Builder and searched a lot for this information and could not find.
I will be very grateful for this information
You generally supply the data to the data grid via it's dataProvider property which is typed as the interface, IList. The IList interface defines a method named getItemAt() that you can use to retrieve an item from a specified array index.
The most common IList implementations are ArrayCollection, ArrayList, and XMLListCollection. Assuming you have created one of these collections and, you can then do something like this:
// note the type of 'item' can be whatever class you're storing in the array
// it doesn't have to be 'Object'
var item:Object = myCollection.getItemAt(0);
If you need more help than this, you need to show the code that you're using.