On Jan 17, 2008 4:10 PM, applecoremilo <[EMAIL PROTECTED]> wrote:

>  i thought that each object i create is its own instance in memory,
>  therefore when i apply an event listener that event is it's own
>  entity for each object regardless of naming.

Each object you create is its own instance in memory. However, the
scope of the variable which references that object is that of the
function, not the loop iteration in which you create the object. In
other words, the following is valid code:

function bar():void
{
    for (var i:int = 0; i < 5; i++)
    {
        var myCanvas:Canvas = new Canvas();
        myCanvas.backgroundColor = "red";
    }

    myCanvas.backgroundColor = "blue";
}

The above code will create 5 separate Canvas objects and set the
background color of each Canvas to red. Then it will set the
background color of the 5th Canvas to blue. The point is that even
though it looks like you are defining the variable within the loop,
which in other languages like Java will limit the scope of that
variable to the end of a loop iteration, in ActionScript3 that
variable is still usable outside of the loop because all local
variables are scoped to the function itself.

This behavior of ActionScript3 is also present in JavaScript, FWIW.

>  Or is there a smarter way of doing it, any links where i can read up
>  on this would be appreciated.

I would do what Gordon suggested in an earlier response to this thread
and define a non-anonymous event handler function to handle the event,
and in that function you can change the background color. You can get
a reference to the object from the drag event. (Remember that in some
cases you have to store the object in the drag event as a data for a
given format, so you might need to change some code there.)

e

Reply via email to