how to reset an array index? actionscript3 - actionscript-3

I got a problem with processing an array in actionScript. I removed the last element of an array through array.pop(). After that I would like to put this removed display-object back to the beginning of the array: array.unshift(object). The object is now the first element of the array but it got still its old label (number of the last element). Therefor I can't update the position (graphically) of the display object. Is it possible to "reindex" the array?

A popped element will not keep it's index, since it will be taken out of the array. If you're trying to unshift(array[i]) after popping array[i], you get an error for referencing an index that no longer exists.
In order to do what you're describing, you can say array.unshift(array.pop()) and then reference the moved element at array[0].
I used the above method when I created an endlessly looping slideshow.
Edit.
It seems I misunderstood your problem slightly. IIRC it is not possible to manipulate an array you're traversing over.
Please post the snippet you're having trouble with for a more educated answer.

Related

Transformers cannot loop over list elements

I am trying to figure out with ESB. Software Ag Designer.
I am getting error.
Transformers cannot loop over list elements.
When I am doing transform.
Please help.
The documentList that you are trying to calculate the size of relatedPartyRef is a part of another Document List requestedTimeSlot. Please loop over the first DocumentList requestedTimeSlot and find the size of child DocumentList inside the loop.
If I see it correctly in your screenshot, in your "sizeOfList" transformer you are not getting the reference to the single "requestedTimeSlot" item in the loop, but to the whole "searchTimeSlot/requestedTimeSlot[]" array (notice the difference in the icons between your screenshot and the example below).
Try removing the map step containing the transformer and adding it back again. If that does not help, maybe you need to install the latest fixes for your version.
Example of mapping in nested loop
hope this helps

Clicking Objects in AS3

I'm new to Actionscript 3 and I'm trying to learn as much as I can.
I want to know how to move objects by clicking.
For Example: I will first click on object to select it then I will click on another object(not in the same location) to place the first one on top of it.
*Sorry if my explanation is bad
I don't have the code to show you because I don't know how to do it.
But the way that I thought of is:
- I will click on the first object to select it and that object will go to an array
- That array will have the function of the second click which will transfer the object on top of another one.
The problem is that there is chance that i can select two objects on the first one (It should be only one). Is there any way to fix this? Or is there a way to make this easier?

setChildIndex to value directly below target object

Looking to set an objects index value to -1 that of the specified object.
this.setChildIndex(box, circle.index-1);
I thought this would work but I apparently I am wrong.
I am trying to get the box directly below the circle index which has an index value that changes constantly. Does anyone know how to accomplish this?
using the getChildIndex method I was able to accomplish this
solution:
this.setChildIndex(box, this.getChildIndex(circle)-1);

How To Merge Objects In AS3, So That They Become Draggable as a Whole

I'm quite new to as3, and I'm heading with a (for me complex) problem.
I have some identical objects (movieclips), wich I made draggable sqaures.
But I want to achieve the following thing:
When I drag one of these objects to another one, I want them to "attach" to each other, just like in some "building games".
And after two (or more) objects are attached, I need them to be draggable as a new whole.
Which means if you click on any of them, every object drags along, en they stay om the same attached position.
I honestly don't know how to do this.
I would appreciate if anyone could provide some examples or code.
Thanksin advance!
Here's a simple algorithm for you:
1) Make an array that will hold "draggable" objects.
2) Upon selecting the first object add it to the array.
3) On FRAME_ENTER move (translate) all the object that are in the draggable array and check objects in the array collision with other objects. If the collision is true, add those objects to the draggable item array.
People here won't write code for you, it's up to you. But if you run into a problem where your code does not work how you intend it, feel free to post it and surely some help will come!

what is the programmatic parlance for this phenomenon?

Here is javascript code (jquery) for adding a row of images:
var tr = $('<tr>');
var td = '<td><img src="myimg.jpg"/></td>';
tr.append(td).append(td).append(td);
$('#mytable tbody tr:eq(0)').before(tr);
tr.empty(); //I really don't need this line...
Technically tr.empty() shouldn't have worked. It actually does the opposite of what I want. What is the techinical term for this behaviour - You've added tr to the DOM, but any jquery function calls to that object still works, where as you'd normally not expect it to work i.e. make changes to the DOM?
I think you have a case of a shared mutable object. You are modifying the object in one place and are surprised to see the changes visible in another place. It's not technically wrong; it's just what happens when you have multiple references to an object that can be modified.
If there is a particular term for this other than 'object reference', I don't know what it is. I'd suggest that your expectation:
any jquery function calls to that object still works, where as you'd normally not expect it to work i.e. make changes to the DOM?
should be adjusted - for object variables, one should expect that whichever particular reference a change is made through, all references see the updated object.