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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:39:27+00:00 2026-05-11T22:39:27+00:00

I have this small class called City that simply holds some information about a

  • 0

I have this small class called City that simply holds some information about a city, here it is:

class com.weatherwidget.City {
    var zipCode:String;
    var forecastText:Array = new Array(5);
}

When I have an array of cities and I change one of the forecastText of one city it will change that forecastText for all of the cities.

For example:

import com.weatherwidget.City;

var arr:Array = new Array();
arr.push(new City());
arr.push(new City());

arr[0].forecastText[0] = "Cloudy";
trace(arr[0].forecastText[0]);
trace(arr[1].forecastText[0]);

Will have the following output:

Cloudy
Cloudy

Even though I only changed arr[0].forecastText[0]. I think I must be misunderstanding something about arrays in objects for actionscript 2.

  • 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-11T22:39:27+00:00Added an answer on May 11, 2026 at 10:39 pm

    well the reason why … hmmm … little complicated to explain …

    alright … ActionScript is prototype-oriented, as is ECMA-script … classes are only a syntactic sugar introduced by actionscript 2 (this has changed yet again in as3, but that’s a different subject) …

    so if this is the original code:

    class com.weatherwidget.City {
        var zipCode:String;
        var forecastText:Array = new Array(5);
    }
    

    then this is, what actually happens:

    //all classes get stuffed into _global, with packages being a property path:
    if (_global.com == undefined) _global.com = {};
    if (_global.com.weatherwidget == undefined) _global.com.weatherwidget = {};
    //and the actual definition:
    _global.com.weatherwidget.City = function () {};
    _global.com.weatherwidget.City.prototype = { forecastText:new Array(5) }
    

    the prototype object of City, that serves as prototype for instances of City, has a property called forecastText, which is an Array of length 5 … so when looking up forecastText on an instance of City, it cannot be found directly and will be looked up in the prototype chain … it will be found in the instance’s prototype … thus, all instances share the same Array …

    the difference is, that the second example gets translated to:

    //same thing here:
    if (_global.com == undefined) _global.com = {};
    if (_global.com.weatherwidget == undefined) _global.com.weatherwidget = {};
    //and the actual definition this time:
    _global.com.weatherwidget.City = function () { this.forecastText = new Array(5); };
    _global.com.weatherwidget.City.prototype = {}
    

    as you might have noticed, declared members are only a compiletime thing … if nothing is assigned to them, they simply will not exist at runtime …

    well, this explenation requires, that you either know JavaScript or ActionScript 1 a little, but i hope it helps …

    greetz

    back2dos

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

Sidebar

Related Questions

I have this method in an exterior class that gets called whenever the charachter
I have this small PHP script that takes a POST variable and writes it
I have this small piece of code that basically takes a list and runs
I have this string: small: http://img.exent.com/free/frg/products/666550/player_boxshot.jpg boxshot: http://img.exent.com/free/frg/products/666550/boxshot.jpg I want to get only the
I am writing a small mocking class to do some tests. But this class
We have small class, that has a related class class Car has_one :engine, :dependent
Hi I have a class called ColorChooser (in the net.java.dev.colorchooser.ColorChooser package) This is a
i'm trying to write a small java class. I have an object called BigNumber.
I have a small problem. I am testing my Android REST class on http://www.thomas-bayer.com/sqlrest/CUSTOMER
i have a small doubt that how to call a method form one class

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.