Shortening this simple code in Actionscript? - actionscript-3

http://imgur.com/3wJBwl6
As you can see on the picture, I have a stupidly long code, just to get the information I want in the Comboboxes. Is there any way to make it so I dont need that long of a code?
The comboboxes should display the same information, yet be able to record different "results"
Im obviously a beginner programmer. Help would be appreciated.

First, create an array with the data you need, for example:
var dataArray:Array = [{label:"label1", data:"data1"}, {label:"label2", data:"data2"}];//as many objects as you need.
then name the dropdown lists and use the "dataProvider" property to populate it:
dropdown1.dataProvider = new DataProvider(dataArray);
dropdown2.dataProvider = new DataProvider(dataArray);
dropdown3.dataProvider = new DataProvider(dataArray);
....
P.S. don't forget to import:
import fl.data.DataProvider;

Related

How can I use Json patch document using VB.net

I'm struggling to use the Add method for Json Patch Document in vb.net? My goal is to create work items programmatically. I'm looking to add values to Title, Description and Priority field of a work item. Do I have to use the same code separately for all three fields?
Also, I'm new to all this development stuff so encouragement would be appreciated. Here is my mini code - just updated. Can anyone tell me if I'm doing it the right way.
Dim JPDocument As New JsonPatchDocument
With JPDocument
.Item(0).Operation = Operation.Add
.Item(0).Path = "/fields/System.Title"
.Item(0).Value = "Visual basic rocks"
End With
Thanks,
Omar

Razor WebPage: How to make data from the database alvailable to several pages?

My question is quite similar to this one.
I get the same data (attributes of objects, each row represents an object) from the database for two of my pages, one page to edit the data and one page to view it. To reduce redundant code and to improve maintaining I wanted to write the piece of code that loads the data only once.
My idea was to use a _PageStart.cshtml. But with that I only can store strings in the PageData array but not Objects.
So what is the best way to make the rows from the database available on several pages?
Here is how I get the data from the database:
var db = Database.Open("mydb");
String query = "select * from motors";
var rows = db.Query(query);
System.Data.DataTable motors = new System.Data.DataTable();
motors.Columns.Add("posX", typeof(int));
motors.Columns.Add("posY", typeof(int));
IEnumerator<dynamic> en = rows.GetEnumerator();
while (en.MoveNext()) {
motors.Rows.Add(en.Current.posX, en.Current.posY);
}
I would like to access the DataTable motors on different pages.
All you have to do is create a page that only has your code in it, Then on whatever page you want it displayed just use:
#RenderPage("~/yourpage.cshtml");

Is it possible to cast Json fields when loading them into pig?

I was wondering if there is a way to cast a field that comes in through the JsonLoader(). This is basically what I want but it doesn't work.
Person = LOAD 'people' USING JsonLoader() AS (name:chararray)
I haven't tried with JsonLoader, but i have faced a similar situation with HCatLoader.
There i did the casting in the second line.
Person_tmp = LOAD 'people' USING JsonLoader();
Person = FOREACH Person_tmp GENERATE name:chararray;
Just try it out. It might work out.

Date And Time Shown Whithout Updating AS3

I am currently trying to show local date and time (of any user that will view my animation)
in a dynamic text field (instance name:DateTime).
i found many tutorials and methods but what i want to do is show current date and time whithout updating seconds/minutes or anything. Just static date and time when the movie entered the frame.
I am using ActionScript3.
I apologise if i am not very clear. can't really express my self in english
Thanks in advance
//...
var d:Date = new Date();
var dateText:String = d.toLocaleString();
DateTime.text = dateText;
//suggestion: dont use capital letters for instance names
//keep them for class names
Date is top level afaik so you don't need to import it.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Date.html
also if you post some code with your question next time it is easier to help

Accessing variables outside class

I will try to explain my issue as good as I can.
I have a class with functions, the purpose of one function is to fetch information from the database and display it.
Everything works as it should, but now I need to access some variables to use them outside my class in another file, I don't know how this should be done so I'm wondering if someone can guide me.
function fetch(){
$this->_select_query = '
SELECT movies_id, movies_title, movies_director, movies_year, movies_category_id, cat.name
FROM movies
LEFT JOIN cat ON id = movies_category_id'
or die(mysqli_error());
$this->_stmt = $this->_mysqli->prepare($this->_select_query);
$this->_stmt->execute();
$this->_stmt->bind_result($this->_select_id, $this->_select_title, $this->_select_director, $this->_select_year, $this->_select_category_id, $this->_select_category_name);
$this->_stmt->store_result();
while($this->_stmt->fetch()){
echo '<tr>
<td>'.$this->_select_title.'</td>
<td>'.$this->_select_director.'</td>
<td>'.$this->_select_year.'</td>
<td>'.$this->_select_category_name.'</td>
<td>Edit</td>
<td>Delete</td>
</tr>
';
}
}//close function fetch
The function fetch is inside a class called movies, now on another page I have a form to edit(update) these movies and I would like to return the title, director etc.. inside that form so it is easy to notice what you are changing.
Now I do know how to do this using php procedural but not with object oriented php.
As you can also notice here I echo out the whole table (another part of the table is on a diffirent page)
So because of this I can't use $movies->fetch()
I do hope someone can give me some more information on my issue since I feel a bit lost at this point, and while staring too much on the same code you can become confused and mix up stuff.
Kind Regards
Edit: should I be using globals, constants ?
You should refactor your code.
As you are saying, you can't do $movies->fetch() since it echoes the table. That's a sign of braking the Single Responsibility Principle. You should divide your function into two: one function that fetches (and returns) the data, and another one that takes data as a parameter and returns a table with the data.
That way, you can reuse the first one when you want to get the values for the edit form.
Since you have a procedural background, I'd recommend that you create a new class that represents a "movie" that has the required fields. Then, for each row in your table you should create an instance of that class and populate the fields, and ultimately return all those instances.
Sorry for not posting any code at the moment, I realized that would have been easier.