Hi everyones…
I Was kind of at My Wit’s End…Im totally have no idea what happen???I have decide to using factory class to attach MovieClip from library.So far everythings its work great only when i try to add extra property it thrown this error…so hope someone can enlighten me what happen actually…is it because I cast the object to MovieClip???..
the fla:
var car:Main = new Main(stage);
car.attachCar("SubaruImpreza");
main.as
package{
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.DisplayObjectContainer;
import flash.events.Event;
public class Main extends Sprite{
private var _stage:DisplayObjectContainer;
private var totalcar:Number = 5;
public function Main(stage_:DisplayObjectContainer){
_stage = stage_;
}
public function attachCar(_carName:String):void{
for(var i:int=0;i<totalcar;i++){
var thecar:ICar = CarFactory.getCar(_carName);
(thecar as MovieClip).x = Math.random()*500+25;
(thecar as MovieClip).y = Math.random()*350+25;
** //the issues raiseup here...when I add this extra property its thrown this error**
[COLOR="black"][COLOR="black"]ReferenceError: Error #1056: Cannot create property anglez on SubaruImpreza.[/COLOR][/COLOR]
at Main/attachCar()
at thefla_fla::MainTimeline/thefla_fla::frame1()
(thecar as MovieClip).anglez = Math.random()*6.28318531;
_stage.addChild(thecar as MovieClip);
thecar.speeding();
}
}
}
}
factory class
CarFactory.as
package{
public class CarFactory{
public static function getCar(type:String):ICar{
switch(type){
case "SubaruImpreza":
return new SubaruImpreza();
break;
case "Evo":
return new Evo();
break;
case "FairLady":
return new FairLady();
break;
default :
return null;
break;
}//end switch
}
}
}
Interface
ICar.as
package{
public interface ICar{
function speeding():void;
}
}
and the rest class Evo.as,SubaruImpreza.as,FairLady.as…
I’ve been struggling to remedy to no avail so I really need help onthis at least point me for the rite path…
u can grab the file here…
http://www.franzacollections.net/fifin04/forum/thewoes.zip
Tq in advances