|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
class problems
I'm having a problem with classes. I have two class definitions, photo and photoCategory as follows:
Code:
class photo
{
var fileName:String; this.caption = caption;
}
}
class photoCategory
{
var name:String;
var photos_arr:Array = new Array();
var path:String;
function photoCategory(name:String,path:String)
{
this.name = name;
this.path = path;
}
function addPhoto(thePhoto:photo)
{
photos_arr[photos_arr.length] = thePhoto;
trace("adding photo: "+thePhoto.fileName+" to category: "+name+", total length is now: "+photos_arr.length);
}
}
when I add many photos to multiple categories, this is the output: Code:
...
adding photo: 27.jpg to category: category1, total length is now: 27
adding photo: 28.jpg to category: category1, total length is now: 28
adding photo: 29.jpg to category: category1, total length is now: 29
adding photo: 30.jpg to category: category1, total length is now: 30
adding photo: 01.jpg to category: category2, total length is now: 31
adding photo: 02.jpg to category: category2, total length is now: 32
adding photo: 03.jpg to category: category2, total length is now: 33
adding photo: 04.jpg to category: category2, total length is now: 34
adding photo: 05.jpg to category: category2, total length is now: 35
adding photo: 06.jpg to category: category2, total length is now: 36
adding photo: 07.jpg to category: category2, total length is now: 37
var caption:String;
function photo(fileName:String,caption:String)
{
this.fileName = fileName;
...
As you can see, when the category changes, the array length keeps going up. It is almost as if the two arrays for the two different categories are not independent. I don't know what could be causing this, can sombody help me out? |
|
#2
|
|||
|
|||
|
Hi, what happens if you re-init the array:
Code:
class photoCategory
{
var name:String;
var photos_arr:Array = new Array();
var path:String;
function photoCategory(name:String,path:String)
{
this.name = name;
this.path = path;
this.photos_arr = new Array();
}
function addPhoto(thePhoto : photo)
{
this.photos_arr[this.photos_arr.length] = thePhoto;
trace("adding photo: "+thePhoto.fileName+" to category: "+name+", total length is now: "+this.photos_arr.length);
}
}
|
|
#3
|
||||
|
||||
|
Thanks Tann, I changed it to the following and it worked fine:
Code:
class photoCategory
{
var name:String;
var photos_arr:Array;
var path:String;
function photoCategory(name:String,path:String)
{
this.name = name;
this.path = path;
this.photos_arr = new Array();
}
function addPhoto(thePhoto : photo)
{
this.photos_arr[this.photos_arr.length] = thePhoto;
trace("adding photo: "+thePhoto.fileName+" to category: "+name+", total length is now: "+this.photos_arr.length);
}
}
|
![]() |
| Viewing: Dev Shed Forums > Web Design > Flash Help > class problems |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|