Just in pseudo code to figure a possible way to deal with this issue.
On the timeline :
import com.fruits.Fruit;
import com.fruits.Melon;
import com.fruits.Apple
var fruit_1:Melon = new Melon();
var fruit_2:Apple = new Apple();
if(fruit_1 is Melon){
trace("anyway my SuperclassName is : " + fruit_1.getType());
trace (fruit_1.getMyType());
trace("");
}
if(fruit_2 is Apple){
trace("anyway my SuperclassName is : " + fruit_2.getType());
trace (fruit_2.getMyType());
trace("");
}
in com.Fruit.as :
package com.fruits {
public class Fruit {
import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName;
import flash.utils.getQualifiedSuperclassName;
public function Fruit() {
trace ("I'm a Fruit");
}
public function getType():String{
var type:String = getQualifiedSuperclassName(this)
var str:String = (type);
return str;
}
}
}
In com.Melon :
package com.fruits {
public class Melon extends Fruit {
import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName;
import flash.utils.getQualifiedSuperclassName;
public function Melon() {
super();
trace ("Melon says : ");
trace (" because I'm Fruit and not happy to be a Melon");
trace("");
}
public function getMyType():String{
var type:String = getQualifiedClassName(this)
var str:String = ("Im a " + type);
trace("Class said : I worth nothing because I'm an Fruit and not proud to be an Melon");
str += "\n" + "but in fact I'm a " + getQualifiedSuperclassName(this)
return str;
}
}
}
In com.Apple :
package com.fruits {
public class Melon extends Fruit {
import flash.utils.getDefinitionByName;
import flash.utils.getQualifiedClassName;
import flash.utils.getQualifiedSuperclassName;
public function Melon() {
super();
trace ("Melon says : ");
trace (" because I'm Fruit and not happy to be a Melon");
trace("");
}
public function getMyType():String{
var type:String = getQualifiedClassName(this)
var str:String = ("Im a " + type);
trace("Class said : I worth nothing because I'm an Fruit and not proud to be an Melon");
str += "\n" + "but in fact I'm a " + getQualifiedSuperclassName(this)
return str;
}
}
}
This is just an idea, tell me more about your target and if this may help You...
Best regards Nicolas.
PS : I'm sorry but my English is really bad. so I tried to figure me the issue...
You may perhaps forget about indexOf and use addChild anytime You want to set an object/instance over another one....
So You don't have to check about the indexes.
addChild(some old Child) will make the "old Child" be on the the last index (over the other instances).
Sorry I didn't wrote your code but the title said that you want to check if the fruit is a Melon or an Apple...
Sorry if I misunderstood. :(
appelsOnstage?