Weird problem with a custom bindable class and a vector - apache-flex

I'm having a very weird problem with a vector in my application.
Details...
I have the following classes.
Person,Player,PlayerController.
Player extends Person. Person extends ObjectProxy in order to enable binding.
So the Player class has the [Bindable] tag.
The PlayerController class contains a remote object calling a php method to receive a firstname and a lastname and when the CallResponder gets the result from the call,the result handler creates a Player instance. At that moment I am trying to push the player object into a Vector..
The problem is the following.
Every time the push method is called, the vector is being populated with the last player that was created but not just in the end of the vector. It replaces the other instances as well! So the vector always contains the most recent player instance but in every position of it. :S
I have also tried doing it with an Array and the results are the same.
Any thoughts on what I'm doing wrong? It's driving me crazy. :S

My guess is that you are pushing the same object reference into your vector after setting that reference to a new instance of Player, meaning that all of the items in your vector refer to the same object, which is always the newest object. I say "guess" because I haven't seen your code. What are you pushing into your vector, a local variable? A member variable?
Edit: Based on your comment below, try adding your new Player object to your vector using a local variable rather than from your member variable (player_):
var newPlayer:Player = new Player();
newPlayer.firstName = results[firstName];
newPlayer.lastName = results[lastName];
players_.push(newPlayer);
player_ = newPlayer;
You are doing what I suspected, which is adding multiple references to the same object to your vector. Since all of the references in your object refer to the same object, changing the one object changes ALL of the entries in your vector. Doing the above will create a brand new (and unique) Player object each time you add to your vector.

Related

Player:GetAccountId() is passed a table argument

I've been trying to use
local function TestFunction(event, player, command)
local accountId = Player:GetAccountId()
end
whichs 2nd line was copied straight from the ElunaLua wiki.
On execcution I received the error
calling 'GetAccountName' on bad self (bad argument : Player expected, got table)
I suspected the "Player" to be a global argument, wondering how it can be a table and how to use said table?
"Player" is actually a global table that holds the functions you can use on a Player type variable.
So that player has all functions in "Player" table.
This is why doing Player:GetAccountId() caused a bit of a different error than something like Player variable not existing.
To make it work, i used "player:GetAccountId()" instead of a capital P. This passes the method the variable named "player".

Adding elements from vector to listBox in c++

Im new programmer, learning C++ nearly 15 weeks so far and I'm doing a small project about student database with GUI ( Windows-forms ). I created GUI with Drag n Drop thing in Visual Studio 2015.
I have class Student with 13 variables including getters and setters (Index, First Name,Last name, etc...). I've successfully opened connection with MySQL database for Adding, Deleting and Update students.
And I also wrote objects String^ to pick text from my TextBoxes and then parse them into normal string with msclr/marshal.
Now, problem is when i create object of Student and after adding it into vector with code below:
vector<Student> vektor;
Student *s = new Student(iIndeks, cIme, cPrezime, cDatumRodjenja, cFakultet, cSmer, cEmail, iBrTelefona, cDrzava, cMesto, cUlicaIBroj, cOpstina, iPostanskibr);
vektor.push_back(*s);
Im unable to add elements of that vector into listBox with:
listBox1->Items->Add(vektor);
It says this error:
Function cannot be called with given argument list,
argument types are:
(std::vector<Student, std::allocator<Student>>) object type is:
System::Windows::Forms::ListBox::ObjectCollection ^.
I guess its pretty self-explaining but I have no idea (should I or not) create my class like the ref class or something like that?
Any suggestion what this newbie can do?
Thanks for help.

call ds_list from diffrent object error

I have created a textbox object and in its create event it creates list like
lines = ds_list_create();
in step event of textbox I use ds_list_add(lines, "line one");
and it works fine.
Now I have a diffrent object that try to call ds_list_add(Textbox.lines, "line from diff object");
but on running it gives error about var not set before reading. i tried also to change to global.list = ds_list_create(); and still same problems.
can someone explain how to call ds_list from diffrent object.
You can call ds_list_* functions right like you did. Just, you must make sure the data structures a function is referring to does actually exists.
I tried the following for testing purposes. Create two objects, objTextBox and objOther and set their events as follows.
For object objTextbox:
Create Event
list = ds_list_create();
Press 'Space' Event
var str = get_string("I'm objTextbox:","");
ds_list_add(list,str);
Draw Event
for (var i=0;i<ds_list_size(list);i++)
draw_text(10,10+15*i,string(ds_list_find_value(list,i)));
For object objOther:
Press 'Shift' Event:
var str = get_string("I'm objOther:","");
ds_list_add(objTextbox.list,str);
Now add them to a room, and make sure first object to be created is objTextbox, which is the one creating the ds_list. Run.
When dealing with data structures, always make sure they were created before working with them.

How to assign Custom Activity Result to a Root level variable at Runtime (in Custom Activity Execute method) in workflow?

Assume that I have a workflow with 3 Custom Activities which are placed in a Sequence Activity. And I created a Boolean variable (name it as “FinalResult”) at Sequence Activity level (Root) to hold the Result. My Intention is, I want to assign each Custom Activity Result to Root level variable (“FinalResult”) within the Custom Activity Execute method after finishing the activity.
I can get this by declaring the output argument in Custom Activity and placing the variable name at design time in the properties window of activity manually while designing the policy.
But I don’t want to do this by the end user. I want just the end user drag and drop the activities and write conditions on the” FinalResult” variable. Internally I have to maintain the Activity Result in “FinalResult” Variable through programmatically.
Finally I want to maintain the workflow state in “FinalResult” variable and access it anytime and anywhere in the workflow.
I tried like this below getting error "Property does not exist".
WorkflowDataContext dataContext = context.DataContext;
PropertyDescriptorCollection propertyDescriptorCollection = dataContext.GetProperties();
foreach (PropertyDescriptor propertyDesc in propertyDescriptorCollection)
{
if (propertyDesc.Name == "FinalResult")
{
object data = propertyDesc.GetValue(dataContext);// as WorkUnitSchema;
propertyDesc.SetValue(dataContext, "anil");
break;
}
}
Please let us know the possible solutions for the same.
I do this all the time.
Simply implement IActivityTemplateFactory in your activity. When dragged and dropped onto the design surface, the designer will determine if your activity (or whatever is being dropped) implements this interface. If it does, it will construct an instance and call the Create method.
Within this method you can 1) instantiate your Activity and 2) configure it. Part of configuring it is binding your Activities' properties to other Activities' arguments and/or variables within the workflow.
There are a few ways to do this. Most simply, require these arguments/variables have well known names. In this case, you can simply bind to them via
return new MyActivity
{
MyInArgument = new VisualBasicValue<object>(MyActivity.MyInArgumentDefaultName),
};
where MyActivity.MyInArgumentDefaultName is the name of the argument or variable you are binding to.
Alternatively, if that variable/argument is named by the user... you're in for a world of hurt. Essentially, you have to
Cast the DependencyObject target passed to the Create method to an ActivityDesigner
Get the ModelItem from that AD
Walk up the ModelItem tree until you find the argument/value of the proper type
Use its name to create your VisualBasicValue
Walking up the ModelItem tree is super duper hard. Its kind of like reflecting up an object graph, but worse. You can expect, if you must do this, that you'll have to fully learn how the ModelItem works, and do lots of debugging (write everything down--hell, video it) in order to see how you must travel up the graph, what types you encounter along the way, and how to get their "names" (hint--it often isn't the Name property on the ModelItem!). I've had to develop a lot of custom code to walk the ModelItem tree looking for args/vars in order to implement a drag-drop-forget user experience. Its not fun, and its not perfect. And I can't release that code, sorry.

Reloading a component but maintaining the same instance in Flex

Let's say that I have a canvas component called myCanvas and I instantiated it with
var myCanvasPage:myCanvas = new myCanvas;
this.addChild(myCanvasPage);
Then I want to essentially reload myCanvasPage later on. In effect I want to do this:
this.removeChild(myCanvasPage);
var myCanvasPage:myCanvas = new myCanvas;
this.addChild(myCanvasPage);
except instead of creating a new instance of myCanvas, I want to use the already created instance of myCanvas and essentially reload or re-create it but making sure that the instance name and references to it remain the same. What would be the best way to do this?
Whenever you do
var myCanvasPage:myCanvas = new myCanvas;
you are instantiating the myCanvasPage Object.
Removing an object from the stage will not delete the Object from memory.
As long as there is a reference somewhere in your code the myCanvasPage Object will not be garbage collected and all the values and attributes will be the same as at the time you removed it from the stage.
To make that reference you have to scope it to your class.
public var myCanvasPage:myCanvas = new myCanvas;
So now you would reference it with
this.myCanvasPage
and when you are ready to add it back to the stage.
this.addChild(this.myCanvasPage);
So to recap you can add and remove an Object from stage
this.addChild(this.myCanvasPage);
this.removeChild(this.myCanvasPage);
all day long and the data in that object will never go away.
Some good reading on garbage collection
What do you mean as "reloading"? Maybe it is simpler to create data-driven components and change that data to change or reset component state>
Woa I'm not sure where to start here... I think THE_asMan addresses most of your misunderstandings. The missing bit I think you need to look into is how a reference to an object holds (i.e. is counted) as long as it doesn't go out of scope. Just keep in mind that as long as the a variable is not out of scope, its reference to some object (if there is one, i.e. if it is not null) is counted.
http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f9d.html#WS5b3ccc516d4fbf351e63e3d118a9b90204-7f8c

Resources