Jump to content
Search Community

Adding Sprites To Stage From Library

Buzzafett test
Moderator Tag

Recommended Posts

Need help with this please, nearly there but I am getting an error.

Using a function to add sign_mc1 to sign_mc10 from the library into a container.

I am also sure there's another way to write the code.

 

function stoppedF():void {

var i:Number;

if (wheel_mc.segment_01.hitTestPoint(hitObject.x,hitObject.y,true)) {
zoomSign(i = 1);
output_txt.text = "Hit 01";
}
else if (wheel_mc.segment_02.hitTestPoint(hitObject.x,hitObject.y,true)) {
zoomSign(i = 2);
output_txt.text = "Hit 02";
}
else if (wheel_mc.segment_03.hitTestPoint(hitObject.x,hitObject.y,true)) {
zoomSign(i = 3);
output_txt.text = "Hit 03";
}
else if (wheel_mc.segment_04.hitTestPoint(hitObject.x,hitObject.y,true)) {
zoomSign(i = 4);
output_txt.text = "Hit 04";
}
else if (wheel_mc.segment_05.hitTestPoint(hitObject.x,hitObject.y,true)) {
zoomSign(i = 5);
output_txt.text = "Hit 05";
}
else if (wheel_mc.segment_06.hitTestPoint(hitObject.x,hitObject.y,true)) {
zoomSign(i = 6);
output_txt.text = "Hit 06";
}
else if (wheel_mc.segment_07.hitTestPoint(hitObject.x,hitObject.y,true)) {
zoomSign(i = 7);
output_txt.text = "Hit 07";
}
else if (wheel_mc.segment_08.hitTestPoint(hitObject.x,hitObject.y,true)) {
zoomSign(i = 8);
output_txt.text = "Hit 08";
}
else if (wheel_mc.segment_09.hitTestPoint(hitObject.x,hitObject.y,true)) {
zoomSign(i = 9);
output_txt.text = "Hit 09";
}
else if (wheel_mc.segment_10.hitTestPoint(hitObject.x,hitObject.y,true)) {
zoomSign(i = 10);
output_txt.text = "Hit 10";
}
else {
output_txt.text = "Wrong";
}
}


function zoomSign(i:Number):void {

var myTimeline:TimelineMax = new TimelineMax;

var container:Sprite = new Sprite ();
this.addChild(container);

var sign_mc:MovieClip = new MovieClip;
var si:sign_mc = sign_mc[""+ i];
container.addChild(si);

trace("Loop No. " + i);

// Container Start Position
container.x = 120;
container.y = 120;

// Container Start Rotation
container.rotation = 0;

myTimeline.append(TweenMax.to(container, 1, {x:120, y:120,rotation:0,alpha:1, scaleX:2, scaleY:2, onComplete:completeF,ease:Bounce.easeOut}));
myTimeline.append(TweenMax.to(container, 1, {alpha:0}), 1);
}


function completeF():void {

trace("Do Something");
}

Link to comment
Share on other sites

Hi, when seeking help with an error its best to give us some information on what the error is and where it is happening.

Its tough to look at 70+ lines of code and try to guess.

 

I imagine your problem is happening around line 59.

 

 

if you are dynamically generating the class name with the variable "i" this should do the trick:

http://www.nivas.hr/...names-are-neat/

Link to comment
Share on other sites

The link you posted to "loading movieclips with dynamic class names" works perfectly, thanks.

 

 

var container:Sprite = new Sprite ();
this.addChild(container);

var dynamicClass:String = "sign_mc" + i;
var classRef:Class = getDefinitionByName(dynamicClass) as Class;
var sign_mc:MovieClip = new classRef();
container.addChild(sign_mc);

trace("Loop No. " + i);

 

It was line 59 as you say.

 

Scene 1, Layer 'Actions', Frame 1, Line 154 1046: Type was not found or was not a compile-time constant: sign_mc.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...