A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: AS3 MovieClip in an array problem

  1. #1
    Member
    Join Date
    May 2007
    Posts
    39

    AS3 MovieClip in an array problem

    Error #1034: Type Coercion failed: cannot convert []@229dff21 to flash.display.MovieClip.
    The above is the eror message I get.

    var girl:MovieClip = new ShawlGirl() is an example of the variables I created for the elements in the array
    What I have is an array full of movie clips.
    var myImages:Array = new Array(boy,cat,dog,frog,girl,jumps,runs)
    There is a function that adds a number of these to the display list.My problem is sometimes it adds the elements and at other times I get the above error message.
    In trying to track the error down I added all the images one at a time and they all displayed without difficulty.Its only when adding multiple images that I get the error and that is not always consistant.
    Any help would be just great
    thanks
    Mango

  2. #2
    Junior Member
    Join Date
    Oct 2010
    Posts
    24
    From the error message, it appears you are at some point treating an array as a MovieClip.

    You haven't given a lot to go on, but here are a few of my guesses as to what is happening:
    1. It may be that you try to access/remove an element in the array but don't do it properly. Instead of accessing/removing the element, you may be casting the array itself (or a slice of the array) as a MovieClip.
    2. Another possibility is that you are inserting an ARRAY into the array at certain times instead of inserting a MOVIECLIP into the array. If you were to do this, then you would receive the given error if you accessed the array element and treated it as a MovieClip.

    There is not much more I can do than guess at what is going wrong, as you didn't provide much in terms of code.

    - Byzoomi

  3. #3
    Member
    Join Date
    May 2007
    Posts
    39
    Byzoomi
    Thanks for the replay.What I have is a multidimension array.
    element [0] is an Array of Strings
    element [1] is an Array of Sound files
    element[2] is an Array of MovieClips
    I have done this...var otherVal0:MovieClip = MovieClip(collectFive()[2][0])
    when attempting to cast the first element of the MovieClip Array
    (collectFive() is a function that returns the multi dimensional Array.)
    What happens is when I add more than 3 elements with addChild I get
    TypeError: Error #1034: Type Coercion failed: cannot convert []@292a2ee9 to flash.display.MovieClip.
    I now understand this means that I have not cast the object correctly .How do I cast array elements to Movie clip?

  4. #4
    Junior Member
    Join Date
    Oct 2010
    Posts
    24
    Like I said my previous post, your problem is you are trying to cast an Array into a MovieClip.

    Are you sure collectFive()[2][0] is a MovieClip? If it was a MovieClip, the line of code you gave would work fine. My guess is that collectFive()[2][0] is an Array, not a MovieClip. Check the code where you insert into the array and make sure you are inserting a MovieClip, not an array of MovieClips or something similar.

    - Byzoomi

  5. #5
    Senior Member
    Join Date
    Jul 2008
    Posts
    391
    Posting your code would really help.

    I'm pretty sure the code you gave would work, but maybe you can try
    PHP Code:
    var multiarray:Array = collectFive ();
    var 
    something:MovieClip MovieClip (multiarray [2][0]); 
    You shouldn't even need to cast it into a MovieClip if it already is one.

    Also are you sure all the elements in the [2] index of the multi-array are MovieClips? If they are all custom classes maybe you forgot to extend the MovieClip class in one of them.

  6. #6
    Member
    Join Date
    May 2007
    Posts
    39
    I would like to thank both of you Members for your imput.The proplem has been properly diagnosed and has been resolved. It was about improper casting.
    Thanks again
    Mango

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center