FORUMS: list search recent posts

adding movieclip dynamically

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Marc Poirier
adding movieclip dynamically
on Jan 28, 2011 at 4:10:10 pm

Hello everyone..

I am developing a survey for the iPad. I need to show 4 screens for each questions (they are all different) so what I did is created my screens, converted them to movie clips, then deleted them from the stage and checked the "export for action script" box so I have a class name for each...

I've created an array with the pages names and want to call them on button actions.. this is the error I get

TypeError: Error #1007: Instantiation attempted on a non-constructor.
at survey_fla::MainTimeline/frame1()[survey_fla.MainTimeline::frame1:36]

How can I achieve this?

thx

Marc.

Thanks!

Marky


Return to posts index

demetri tashie
Re: adding movieclip dynamically
on Jan 29, 2011 at 2:30:52 pm

hi marky,

it would be a good idea to include the code, at the very least the parts that are relevant to your question and problem. otherwise, we are just making stabs in the dark.

the error message is suggesting that you did not create the array correctly. there are several different ways to create an array, so you have to be carfeul.

look at these 2 ways, and notice the difference with the use of brackets [ ] or parenthesis ( ) . using the wrong one will cause errors.

var myArray:Array = new Array ( mc1, mc2, mc3 ) // which uses new and parentheseis
and
var myArray:Array = [ mc1, mc2, mc3 ] // which uses brackets

hope that helps


Return to posts index

Marc Poirier
Re: adding movieclip dynamically
on Jan 29, 2011 at 2:38:59 pm

Hi Demetri,

//declaration of the different screen classes
//Right now, there is only 1 question, with 4 screens, and the last //number is the answer number

array = [["Q1_profile","Q1_question","Q1_reponse","Q1_reference",2]];

var currentView:MovieClip = new array[0][0];
//which would assign the first class to a movieClip...
//It needs to do the same thing as if I would have called it directly
//var currentView:MovieClip = new Q1_profile();

addChild(currentView);

hope this helps

Marky

Thanks!

Marky


Return to posts index


demetri tashie
Re: adding movieclip dynamically
on Jan 29, 2011 at 4:43:20 pm

ah, so you are actually asking about and using multidimensional array ( nested arrays ) ?

so, is 'array" the variable name of the nested arrray ? was it declared as such ?

var array:Array = [ ["Q1_profile","Q1_question","Q1_reponse","Q1_reference",2], ["Q2_profile","Q2_question","Q2_reponse","Q2_reference",2] ];

if so, then of course array[0][0] refers to "Q1_profile" which is a String. originally i thought you were saying that what was in the array were 4 movieclips in the Library with class/export names.

if Q1_profile is either the class name or the declared variable , then it is not a String ( which is an important distinction ), so you would not be using quotation marks.

look at this code below. it is just slightly modified, but will now work for you.

remember that if the class/export name is mc1 , a variable for it must be declared before it is used. i chose to call the variable my_mc1 for my class/export movieclip mc1. your names will be different. change them accordingly.

also, notice that i am not using new in declaring the movieclip variable 'currentview'
var my_mc1:mc1 = new mc1();
var my_mc2:mc2 = new mc2();
var my_mc3:mc3 = new mc3();


var mcArray:Array = [ [my_mc1, my_mc2, my_mc3 ] ] ;


var currentView:MovieClip = mcArray[0][0];
addChild(currentView);



hope that helps


Return to posts index

Marc Poirier
Re: adding movieclip dynamically
on Jan 29, 2011 at 5:10:09 pm

Ha!!! you're the man!!!

it works!

So.. quotation marks not good for calling movie clips dynamically!

thanks so much!

Marc.

Thanks!

Marky


Return to posts index

demetri tashie
Re: adding movieclip dynamically
on Jan 29, 2011 at 5:35:49 pm

the array itself doesn't care what's in it - a String, a MovieClip, combination of both, etc.

but if the index that you are calling on in the array was written as a String for a certain purpose, then to call the movieclip with that name, you have to convert that String to a movieclip.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 CreativeCOW.net All Rights Reserved
[TOP]