Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Adding an image to stage using actionscript

Guest
Mar 31, 2013 Mar 31, 2013

I am new to adobe flash cs6 and actionscript and am having trouble doing what should be a simple task. I have created a new project and document class that looks like this:

package  {

   
import flash.display.MovieClip;

   
public class MyClass extends MovieClip {

       
public function MyClass() {

       
}
}

Now all I want to do is programmatically add an image to the stage when running.

So far, I imported the image to the library which is titled mytestimage which i converted to a symbol. The mytestimage symbol has linkage to a class mytestimage which looks like this:

package  {

   
import flash.display.Sprite;
   
import flash.events.Event;

   
public class mytestimage extends Sprite {

       
public function mytestimage () {
            addEventListener
(Event.ENTER_FRAME, enterFrame);
       
}
       
private function enterFrame(e:Event😞void {

           
}
       
}

}

I then updated my document class to the following :

package  {

   
import flash.display.MovieClip;

   
public class MyClass extends MovieClip {

       
public function MyClass() {
           
var myMovieClip = new mytestimage();
            addChild
(myMovieClip);
       
}
}

and when I debug the project nothing errors and the image isn't loaded - all I see is the white stage. Can somebody help me figure out what I am doing wrong here? Thanks

TOPICS
ActionScript
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 31, 2013 Mar 31, 2013
LATEST

The code is fine as you show it, so if there is a problem it might lie in how you configured things.  Did you define MyClass in the Document Class field of the Properties panel?

You say you imported the image to the library and converted it to a symbol.  Did you convert it to a MovieClip?  How did you do the conversion while it is in the library?

Try putting traces in both of your class files to make sure they are being executed, as in....

package  {

   
import flash.display.MovieClip;

   
public class MyClass extends MovieClip {

       
public function MyClass() {

            trace("Document Class works");
           
var myMovieClip = new mytestimage();
            addChild
(myMovieClip);
       
}
}

package  {

   
import flash.display.Sprite;
   
import flash.events.Event;

   
public class mytestimage extends Sprite {

       
public function mytestimage () {

            trace("image class works");
            addEventListener
(Event.ENTER_FRAME, enterFrame);
       
}
       
private function enterFrame(e:Event):void {

           
}
       
}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines