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 4052388
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:18:49+00:00 2026-05-20T14:18:49+00:00

I’m new to flash, actionscript, and the class/method/static/instance paradigm. I do have one class

  • 0

I’m new to flash, actionscript, and the class/method/static/instance paradigm. I do have one class that I use, it loads a png file and adds it to the stage, I can then manipulate it with the mouse. What I want to do is add some text on top of the png file. When the user clicks and drags the png file around, I want the text to stick with it, basically make it part of the png, overlay it, combine them, group them, whatever.

Here is the class I am using to load the png.

package {

import flash.display.MovieClip;
import flash.display.Loader;
import flash.events.*;
import flash.net.URLRequest;

public class element_icon extends MovieClip {
    public function element_icon(type) {
        var imageLoader:Loader = new Loader();
        var theURL:String = "images/" + type + ".png";
        var imageRequest = new URLRequest(theURL);
        imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
        imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
        imageLoader.load(imageRequest);



        function onIOError(e:IOErrorEvent):void{
            var theURL:String = "images/default.png";
            var imageRequest = new URLRequest(theURL);
            imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
            imageLoader.load(imageRequest);
        }

        function onComplete(evt:Event) {
            addChild(imageLoader.content);

        }
    }
}
}
  • 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-20T14:18:50+00:00Added an answer on May 20, 2026 at 2:18 pm

    My answer is essentially the same as Nathan Ostgard, but my answer has the completed class as follows(I rewrote a lot of your class to adhere to common coding conventions as well as improving overall readability):

    package 
    {
        import flash.display.Bitmap;
        import flash.display.Loader;
        import flash.display.MovieClip;
        import flash.events.IOErrorEvent;
        import flash.events.Event;
        import flash.net.URLRequest;
        import flash.text.TextField;
        import flash.text.TextFormat;
        import flash.events.MouseEvent;
    
        public class ElementIcon extends MovieClip 
        {
            private var _bitmap:Bitmap;
            private var _name:String;
            private var _textField:TextField;
    
            private const DEFAULT_URL:String = "images/default.png";
    
            public function ElementIcon(name:String) 
            {
                _name = name;
    
                init();
    
            }// end function
    
            private function init():void
            {
                _textField = new TextField();
    
                loadImage();
    
                addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
                addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
    
            }// end function
    
            private function loadImage():void
            {
                var url:String = "images/" + _name + ".png";
                var loader:Loader = new Loader();
                loader.load(new URLRequest(url));
                loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onLoaderIOError);
                loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
    
            }// end function
    
            private function onLoaderIOError(e:IOErrorEvent):void
            {
                var loader:Loader = new Loader();
                loader.load(new URLRequest(DEFAULT_URL));
                loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
    
            }// end function
    
            private function onLoaderComplete(e:Event):void
            {
                _bitmap = e.target.content as Bitmap;
    
                build();
    
            }// end function
    
            private function build():void
            {
                addChild(_bitmap);
    
                _textField.text = _name;
                _textField.x = (this.width/2) - (_textField.textWidth/2)
                _textField.y = 5;
                _textField.selectable = false;
                addChild(_textField);
    
            }// end function
    
            private function onMouseDown(e:MouseEvent):void
            {
                startDrag();
    
            }// end function
    
            private function onMouseUp(e:MouseEvent):void
            {
                stopDrag();
    
            }// end function
    
        }// end class
    
    }// end package
    

    You can implement is as follows:

    var elementIcon:ElementIcon = new ElementIcon("Image1");
    addChild(elementIcon);
    

    [UDPDATE]

    The following is a screenshot of the application being run(sorry I couldn’t make a gif file so you could see the ElementIcon object being dragged, but I assure you that you can drag it):

    TextOnLoadedImage

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm making a simple page using Google Maps API 3. My first. One marker
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.