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

  • SEARCH
  • Home
  • 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 6373567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:22:48+00:00 2026-05-25T01:22:48+00:00

So I have a function to create images dynamically in as2, telling some parameters,

  • 0

So I have a function to create images dynamically in as2, telling some parameters, the problem I am facing is that I need to add this function to a file that has as3, so is incompatible, can anyone please help me translate it to as3?

   function goGetUrl(dir:String){
    getURL(dir, "_blank");
  }

 function createImage(str:String,
                        movieName:String,
                        nombreIma:String,
                        index:Number,
                        dir:String, 
                        buttonName:String
                        )
    {   
        var mc:MovieClip    = MYMOVIECLIP.createEmptyMovieClip(movieName, MYMOVIECLIP.getNextHighestDepth());
        var image:MovieClip = mc.createEmptyMovieClip(nombreIma, mc.getNextHighestDepth());
        image.loadMovie(str);
        image._y = (index * 160);
        image._x = 10;
        mc.onRelease = function(){
            goGetUrl(dir);
        }
        target = MYMOVIECLIP.attachMovie("MYCUSTOMBUTTONONLIBRARY",buttonName,MYMOVIECLIP.getNextHighestDepth(),{_x: 300, _y: (image._y + 60) });
        target.onRelease = function(){
        goGetUrl(dir);
        }
    } 

So I call it like inside a loop:

for (i=0; i < Proyecto.length; i++) {
    ...
    createImage(imagePro, "nom"+i,"im"+i, i , myurl, "btn"+i);  
   ...
}

For example the getURL(dir, "_blank"); does not work, I think I can chage it by:

navigateToURL(new URLRequest (dir));

also I know that getNextHighestDepth() is not available in as3

  • 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-05-25T01:22:48+00:00Added an answer on May 25, 2026 at 1:22 am

    First, here’s how is looks as a direct translation:

    function goGetUrl(dir:String)
    {
        //getURL becomes navigateToURL
        navigateToURL(new URLRequest(dir), "_blank");
    }
    
    function createImage(str:String,movieName:String,nombreIma:String,index:Number,dir:String, buttonName:String)
    {   
        //replace createEmptyMovieClip with a new movieclip.
        //addChild automatically adds to the highest available depth
        this[moviename] = MYMOVIECLIP.addChild(new MovieClip()) as MovieClip;
        //movieclip no longer has a load method, so use a Loader instead
        this[nombreIma] = MovieClip(this[moviename]).addChild(new Loader()) as Loader;
        Loader(this[nombreIma]).load(str);
        //properties no longer start with an underscore
        Loader(this[nombreIma]).y = (index * 160);
        Loader(this[nombreIma]).x = 10;
        //using an anonymous function here feels dirty
        MovieClip(this[moviename]).addEventListener(MouseEvent.CLICK,function() { goGetUrl(dir) });
        //AS2 identifiers are replaced by class names
        this[buttonName] = addChild(new MYCUSTOMBUTTONONLIBRARY()) as MYCUSTOMBUTTONONLIBRARY;
        this[buttonName].x = 300;
        this[buttonName].y = this[nombreIma].y + 60;
        MYCUSTOMBUTTONONLIBRARY(this[buttonName]).addEventListener(MouseEvent.CLICK,function() { goGetUrl(dir) });
    } 
    

    This is quite unpleasant in AS3 terms. There is lots of casting required and the click handlers are anonymous functions, which is about as slow to execute as an event handler will get. I would personally create a custom class that you can instantiate multiple times, and store the references in a Vector for easy access. Something like this:

    package {
    
        import flash.display.Sprite;
        import flash.display.Loader;
        import CustomLibraryButton;
        import flash.net.URLRequest;
        import flash.net.navigateToURL;
    
        public class CustomImageDisplay extends Sprite
        {
            private var loader:Loader
            private var button:CustomLibraryButton;
            private var link:String;
    
            public var index:int;
    
            public function CustomImageDisplay($index:int,$img:String,$link:String):void
            {
                _index = $index;
                link = $link;
                init($img);
            }
    
            private function init($img:String):void
            {
                //init image loader
                loader = addChild(new Loader()) as Loader;
                loader.load($img);
                loader.x = 10;
                loader.y = _index * 160;
    
                //init button from library
                button = addChild(new CustomLibraryButton()) as CustomLibraryButton;
                button.x = 300;
                button.y = loader.y + 60;
    
                //add a listener to the whole thing
                this.addEventListener(MouseEvent.CLICK, handleClickEvent);
            }
    
            private function handleClickEvent(evt:MouseEvent):void
            {
                navigateToURL(new URLRequest(link), "_blank");
            }
    
        }
    }
    

    You could use that like this:

    var imageButtons:Vector.<CustomDisplayImage> = new Vector.<CustomDisplayImage>(Proyecto.length);
    for (i=0; i < Proyecto.length; i++) {
        imageButtons[i] = this.addChild(new CustomImageDisplay(i,imagePro,myurl)) as CustomDisplayImage;
    }
    

    The cool thing here is that mouse event in the class will bubble, so if you wanted to know which image component had been clicked from your main code you would add a listener to the stage, and check the event object like this:

    this.stage.addEventListener(MouseEvent.CLICK,handleMouseClick);
    
    function handleMouseClick(evt:MouseEvent):void
    {
        if(evt.currentTarget is CustomDisplayImage) {
            trace("The image button index is: " + CustomDisplayImage(evt.currentTarget).index);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I have one JavaScript that creates rows in a table like this: function
I have a ASP table that I create dynamically on the page load event.
I have some divs created dynamically this way: //here goes some loop, and everything
I have a table where i can add rows using clone function like this:
I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)
I have to create the sin function from scratch in my Comp Sci class,
I have a question regarding an update function I created... CREATE OR REPLACE FUNCTION
I have created a function that takes a SQL command and produces output that
Modern browsers have multi-tab interface, but JavaScript function window.showModalDialog() creates a modal dialog that
I have a function that gives me the following warning: [DCC Warning] filename.pas(6939): W1035

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.