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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:02:26+00:00 2026-06-18T23:02:26+00:00

I’m learning how classes work, it’s pretty complicated. I need an example of a

  • 0

I’m learning how classes work, it’s pretty complicated. I need an example of a right object creation. Let’s say I have a MovieClip blueprint in my library. It can be used as an example to create many instances with names that can further be used as objects in code to change their properties. So pretend I have a blueprint “AppleBP”. I set it as Apple class (assume, it creates a file Apple.as?). I need a code that would create (by pushing a button, for example) an instance Apple01 that would appear at a random place on the screen (just to know it’s different from others, I know how to randomize position). Then make Apple02, Apple03, Apple04 and Apple05. If it’s hard to set name to “Apple” + N, it’s ok to stick to an array with names or at least pick it like if(N = 1){//code for Apple01 creation} then N++ etc.

So for now I tried

var Apple01:Apple = new Apple();
Apple01.visible = true; //just in case I can't see it
Apple01.x = 100;
Apple01.y = 100;
TextField01.text = "blahblah"; //to see if code actually works

Apple doesn’t appear, text does. So what am I missing if creating a new class that is a MovieClip blueprint isn’t enough? And how would I pick new names for each new instance so that it had variable String instead of pure name? (so that I could change the name as text + number based on it’s order)

Add:

package  {
import flash.display.Scene;
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.events.*;
import flash.display.*;

public class MyFirstClass extends MovieClip{ 

        //var N:int;
        var n:int;
        var existingApples:int = 0;
        var apples:Array = new Array();     

    public function MyFirstClass():void{
        MakeNewApple();
        MakeNewApple();
        MakeNewApple();
        MakeNewApple();
        MakeNewApple();

        //apple4.x = 5;
        //apple4.y = 5;

        var draggableApple:Apple = apples[0] ;
        draggableApple.addEventListener(MouseEvent.MOUSE_DOWN, draggableApple.onMouseDown) ;
        draggableApple.addEventListener(MouseEvent.MOUSE_UP, draggableApple.onMouseUp) ;
        info01.text = "Did it";
    }
    public function MakeNewApple():void{
        if(existingApples < 5){
        n = existingApples;
        var apple:Apple = new Apple();
        stage.addChild(apple);
        apple.x = (Math.random()*600+100);
        apple.y = (Math.random()*400+100);
        apple.name = "apple" + n;

        apples.push(apple.name);
        existingApples++;
        trace(existingApples);
        trace(apples);
        }
    }
}
}

Apple.as:

package  {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.events.*;
import flash.display.*;

public class Apple extends MovieClip{

    public function Apple() {

    }

    public function onMouseDown(e:MouseEvent):void{
        this.startDrag();
    }
    public function onMouseUp(e:MouseEvent):void{
        this.stopDrag();

    }
}
}
  • 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-18T23:02:28+00:00Added an answer on June 18, 2026 at 11:02 pm

    Here is come commented example:

    package 
    {
        import flash.display.Scene;
        import flash.display.Sprite;
        import flash.events.MouseEvent;
    
        public class Main extends Sprite 
        {
    
            public function Main():void {   
    
                var apples:Array = new Array() ; // Declare and array
                for (var i:int = 0 ; i < 10 ; i++) { //Let's make 10 apples
                    var apple:Apple = new Apple() ; //Create an apple
                    apple.x = Math.ceil(Math.random() * stage.stageWidth)  ; //Assign random x
                    apple.y = Math.ceil(Math.random() * stage.stageHeight) ; //Assign random y
                    stage.addChild(apple) ; //Add it to stage, so we can see them
                    apples.push(apple) ; //Push into array
                }
                //EDITED
                var draggableApple:Apple = apples[0] ;
                draggableApple.addEventListener(MouseEvent.MOUSE_DOWN, draggableApple.onMouseDown) ;
                draggableApple.addEventListener(MouseEvent.MOUSE_UP, draggableApple.onMouseUp) ;
    
            }
    
        }
    
    }
    

    And Apple.as

    package {
        import flash.display.MovieClip;
        import flash.events.Event;
        import flash.events.MouseEvent;
    
    public class Apple extends MovieClip {
    
        public function Apple() {
            this.graphics.lineStyle(2) ;
            this.graphics.beginFill(0x00FF40) ;
            this.graphics.drawCircle(0, 0, 20) ;
            this.graphics.endFill() ;
    
            //addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown) ;
            //addEventListener(MouseEvent.MOUSE_UP, onMouseUp) ;
        }
    
        public function onMouseDown(event:MouseEvent):void {
            this.startDrag() ;
        }
    
        public function onMouseUp(event:MouseEvent):void {
            this.stopDrag() ;
        }
    }
    }
    
    • Also, name of all variables must start with a small letter. myVariable
    • Names of classes must implement CamelCaseClass
    • Names of constants contain only big letters and underscores. MY_CONSTANT
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
this is what i have right now Drawing an RSS feed into the php,
i got an object with contents of html markup in it, for example: string
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a small JavaScript validation script that validates inputs based on Regex. I

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.