A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: problems converting a string into a movieClip name

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    22

    Question problems converting a string into a movieClip name

    My code is below. I have an external Class AS file doing most of my code but I need some of the moviClips to highlight areas (other movieClips) when they're rolled over.

    I've kept instance names the same + an H for their highlights to lessen the amount of code and be able to use array's and for loops.

    my code is below and brings up this error:

    Actionscript Code:
    TypeError: Error #1034: Type Coercion failed: cannot convert "areanaH" to flash.display.MovieClip.
        at EnterpriseZone_fla::Layer1_1/end()

    please help...

    Actionscript Code:
    import flash.display.MovieClip;



    function hArea (e:MouseEvent) {
        var mName:MovieClip;
        mName = MovieClip((e.target.name) + "H");
        mName.gotoAndStop(2);
       
    }


    function end (e:MouseEvent) {
        var mName:MovieClip;
        mName = MovieClip((e.target.name) + "H");
        mName.gotoAndStop(1);
       
    }

    var stopAll:Array = new Array (bHomes1H,areanaH);

    for (var i:int=0;i<stopAll.length;i++){
        stopAll[i].stop();
       
    }

    var rollArray:Array = new Array (bHomes1,areana);

    for (var Mc:int=0;Mc<rollArray.length;Mc++){
        rollArray[Mc].addEventListener( MouseEvent.MOUSE_OVER,hArea );
        rollArray[Mc].addEventListener( MouseEvent.MOUSE_OUT,end );
    }

  2. #2
    Member
    Join Date
    Dec 2009
    Location
    UK
    Posts
    35
    Use getChildByName e.g.:

    var mName:MovieClip = this.getChildByName(e.target.name + "H");

    Cheers,
    Rob

  3. #3
    Junior Member
    Join Date
    Sep 2009
    Posts
    22
    I tried
    Actionscript Code:
    import flash.display.MovieClip;



    function hArea (e:MouseEvent) {
       
        getChildByName(e.target.name + "H").gotoAndStop(2);
       
    }


    function end (e:MouseEvent) {
       
        getChildByName(e.target.name + "H").gotoAndStop(1);
       
    }

    var stopAll:Array = new Array (bHomes1H,areanaH);

    for (var i:int=0;i<stopAll.length;i++){
        stopAll[i].stop();
       
    }

    var rollArray:Array = new Array (bHomes1,areana);

    for (var Mc:int=0;Mc<rollArray.length;Mc++){
        rollArray[Mc].addEventListener( MouseEvent.MOUSE_OVER,hArea );
        rollArray[Mc].addEventListener( MouseEvent.MOUSE_OUT,end );
    }

    and got
    Actionscript Code:
    Symbol 'Layer 1', Layer 'actions', Frame 1, Line 8  1061: Call to a possibly undefined method gotoAndStop through a reference with static type flash.display:DisplayObject.

    sorry

  4. #4
    Member
    Join Date
    Dec 2009
    Location
    UK
    Posts
    35
    MovieClip(getChildByName(e.target.name + "H")).gotoAndStop(2);

  5. #5
    Junior Member
    Join Date
    Sep 2009
    Posts
    22

    Talking

    thanks that works!! brilliant thanks Rob!


Tags for this Thread

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