Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8709151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:18:00+00:00 2026-06-13T04:18:00+00:00

Here i have an actionscript3 code in which i am creating an array of

  • 0

Here i have an actionscript3 code in which i am creating an array of objects. Basically in the array are multiple instances of the same object. I want to make an event listener which calls a function f0 which rotates the object 90 degrees. My problem is i can’t find a way to asign unique identifiers to each object in array, so when i click an object i want it to rotate, but only the first element of the array rotates. I also want to center my rotation so that the object doesn’t rotate in (0,0).

package
{
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.ColorTransform;

public class Main extends Sprite
{
    var array = new Array();
    var i:int;


    public function Main():void
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }



private function init(e:Event = null):void
    {

        for (var i:int = 0; i < 10; i++)
        {
            var asd:Sprite = new Sprite();
            asd.graphics.beginFill(0x0000ff);
            asd.graphics.drawRect(0, 0, 60, 60);
            array.push(asd);
            addChild(array[i]);
            array[i].x = 60 * i ;
            array[i].y = 60 * i ;
            array[i].addEventListener(MouseEvent.CLICK, f0);
            if (i % 2 == 0) {
            asd.graphics.lineTo(asd.x + 60, asd.y + 60);
            }
            removeEventListener(Event.ADDED_TO_STAGE, init);
        }
    }
private function f0(e:Event):void
    {
        array[i].rotation += 90;
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:18:01+00:00Added an answer on June 13, 2026 at 4:18 am

    The event.target points to the object that the event handler was added to, you can use that to rotate the correct sprite.

    private function init(e:Event = null):void 
    {
        for (var i:int = 0; i < 10; i++) 
        {
           createObject(i);
        }
    }
    
    private function createObject(index:int):void
    {
        var asd:Sprite = new Sprite(); 
        asd.graphics.beginFill(0x0000ff); 
        asd.graphics.drawRect(0, 0, 60, 60); 
        array.push(asd); 
        addChild(asd); 
        array[index].x = 60 * index ;
        array[index].y = 60 * index ;
        array[index].addEventListener(MouseEvent.CLICK, f0);
        if (index % 2 == 0) { 
           asd.graphics.lineTo(asd.x + 60, asd.y + 60);
        }
    
    }
    
    private function f0(e:Event):void
    {
        e.target.rotation += 90; 
    }
    

    To rotate a object around it’s center you can do :

    private function rotateAroundCenter (ob:DisplayObject, angleDegrees:Number):void
    {
        var matrix:Matrix = ob.transform.matrix; 
    
        var rect:Rectangle = ob.getBounds(this.parent); 
    
        matrix.translate(- (rect.left + (rect.width/2)), - (rect.top + (rect.height/2))); 
    
        matrix.rotate((angleDegrees/180)*Math.PI); 
    
        matrix.translate(rect.left + (rect.width / 2), rect.top + (rect.height / 2));
    
        ob.transform.matrix = matrix;
    }
    

    This transforms the objects center to (0,0) rotates it and then translates the object back to it’s original position. It will only work if the objects has a parent and it’s width height is non zero.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here I have piece of code, showing example of how I want to update
Hello I have the actionscript code here for a bubble popping game. When the
Here I have a simple php script which displays some values from a database
I got the code from here the Code is not working, I have the
Here's an interesting architectural query. I have a piece of code that needs to
I want to write a function which removes elements from an array of integers
I have an issue in which outdated code removed long ago code in an
Here I have declared another virtual function in Derived class. #include <iostream> using namespace
Here I have to send and receive dynamic data using a SysV message queue.
Here I have a password field: /*********************PASSWORD**********************/ $password = new Zend_Form_Element_Password('password'); $alnumValidator = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.