Actionscript 3 Problem setting Instance Name of a Sprite

Posted on 2009-04-29
Last Modified: 2013-11-11

I am having trouble setting the instance name of my Sprites that get created through a for loop. What I am doing is loading an external gif into a 16 Sprites that gets created in a foor loop...but it seems like it ignores my parameter setter. Please help.

var rows:int = 16;

var boxSpacing:int = 1;

var boxWidth:Number = 65

var boxHeight:Number = 48

var startX:Number = boxSpacing;

var startY:Number = boxSpacing;

var boxIndex:int = 1;

for(var i:int = 1; i <= rows; i++){

var imgLoader:Loader = new Loader();

imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);

imgLoader.load(new URLRequest("people/adam.gif"));

var box:Sprite = new Sprite();

box.x = startX;

box.y = startY;

box.buttonMode = true;

box.alpha = .5; = "video" + boxIndex++;

function loadComplete(evt:Event):void


trace("Image has loaded.");



startY += box.height + boxSpacing;

box.addEventListener(MouseEvent.MOUSE_UP, boxOnRelease);


function boxOnRelease(evt:MouseEvent):void


var videoName:String = "video/" + + ".flv";



Open in new window

Question by:420_dragon
    LVL 11

    Expert Comment

    so basically your trying to load the gif into each sprite as they are created?
    and then use them as buttons?

    Author Comment

    Well yes. Also I am eventually going to use xml to load different images into each gif...but right now..Im just trying to figure out a way to get this to work.

    LVL 11

    Accepted Solution

    you can use the image loaded as a button directly and disregard the sprite.


    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
    Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
    The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
    The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now