PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
controlling movieclip from array - goto inside movieclip
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: controlling movieclip from array - goto inside movieclip

Threaded View

  1. #1
    Flash Genie letschillout's Avatar
    Join Date
    Feb 2007
    Location
    31.52949, 74.347272
    Posts
    146

    Question controlling movieclip from array - goto inside movieclip

    Hi, i have dynamic buttons in movieclip and i want the movieclip goto 2nd frame once some one click single movieclip while rest remains in 1st frame.
    the movieclips can be in array

    i have some code here:

    Actionscript Code:
    var mc:MovieClip = new MovieClip();
    for(var i:int = 0 ; i < numberOfButtons;i++)
    {
                var btn:MovieClip = new button();
                btn.addEventListener(MouseEvent.CLI[QUOTE][/QUOTE]CK, mouseClickHandler);
                btn.x = i * 20;
                btn.name = "btn_" + i;
               
                mc.addChild(btn);
                buttonArray.push(btn.name);
               
    }
    trace(buttonArray);

    basically i want to run this action i.e.

    am calling movieclip name from array to goto 2nd frame

    mc.buttonArray[my_playback_counter].gotoAndStop(2);


    Actionscript Code:
    function mouseClickHandler(event:MouseEvent):void {
        var str:String = event.currentTarget.name;
        var i = str.substring(4,6);
        var thumb_url = BannerArray[i];
        event.currentTarget.gotoAndStop(2);
        trace(event.currentTarget.name);
    }

    how can do it?


    ----------------
    am doing rotating image banner all code is working except the buttons highlighting

    ----------------

    Actionscript Code:
    var my_slideshow:Sprite = new Sprite();
    var my_image_slides:Sprite = new Sprite();
    var my_preloader:TextField;

    var tween:Tween;
    var my_prev_tween:Tween;
    var timer:Timer;
    var my_timer:Timer;
    var BannerArray:Array = new Array();
    var my_loaders_array:Array=[];
    var my_tweens_array:Array=[];
    var buttonArray:Array=[];

    var my_speed:Number;
    var my_success_counter:Number = 0;
    var my_playback_counter:Number=0;

    //total number of images
    var my_total:Number;
    var interval:int = 2000;
    timer = new Timer(interval);

    //loading xml
    var myXML:XML;
    var myLoader:URLLoader = new URLLoader();
    myLoader.load(new URLRequest("banners.xml"));

    //add listener xml
    myLoader.addEventListener(Event.COMPLETE, processXML);

    function processXML(e:Event):void {
    //xml data
    myXML = new XML(e.target.data);
    my_speed= myXML.@SPEED;
    my_total = myXML.spotlight.length();



    //loadin image on stage
    loadimage();

    myLoader.removeEventListener(Event.COMPLETE, processXML);
    myLoader=null;

    //add buttons to stage
    var numberOfButtons:int = myXML.spotlight.length();
    var mc:MovieClip = new MovieClip();
    for(var i:int = 0 ; i < numberOfButtons;i++)
    {
                var btn:MovieClip = new button();
                btn.addEventListener(MouseEvent.CLICK, mouseClickHandler);
                btn.x = i * 20;
                btn.name = "btn_" + i;
               
                mc.addChild(btn);
                buttonArray.push(btn.name);
               
    }
    trace(buttonArray);
    mc.buttonArray[1].gotoAndStop(2);
    addChild(mc);
    mc.x = stage.stageWidth/2 - mc.width/2;
    mc.y = 303;
    //<------- buttons finish -->


    //adding image
    function loadimage():void{

    var imageList:XMLList = myXML.spotlight.image;

        for each (var tempXML:XML in imageList)
        {
            BannerArray.push(tempXML);
        }


    //trace(BannerArray);
    var thumb_url = BannerArray[i];
    var thumb_loader = new Loader();
    thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoadComplete);
    thumb_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler)
    thumb_loader.load(new URLRequest(thumb_url));

       
        //loading text
       
        my_preloader = new TextField();
        //my_preloader.text="LOADING...";
        my_preloader.autoSize=TextFieldAutoSize.CENTER;
        my_preloader.x = (stage.stageWidth - my_preloader.width)/2;
        my_preloader.y = (stage.stageHeight - my_preloader.height)/2;
        addChild(my_preloader);
       
       
    }



    //adding image to stage
    function imageLoadComplete(e:Event):void{


    //var my_thumb:Loader = Loader(e.target.loader);
    //mycontainer.addChild(my_thumb);
    //var myTween:Tween = new Tween(my_thumb, "alpha", Strong.easeOut, 0, 1, 2, true);
    if (BannerArray.length == my_total)
    {
    startShow();

        }

        var my_loaderInfo:LoaderInfo=LoaderInfo(e.target);
        my_loaderInfo.removeEventListener(Event.COMPLETE, imageLoadComplete);



    }

    function ioErrorHandler(e:IOErrorEvent):void{
        trace(e.text);
    }


    function startShow():void {

        removeChild(my_preloader);
        my_preloader=null;

        //addChild(my_slideshow);
        mycontainer.addChild(my_image_slides);
       
        nextImage();

        my_timer=new Timer(my_speed*1000);
        my_timer.addEventListener(TimerEvent.TIMER, timerListener);
        my_timer.start();
        //trace(my_timer);

    }

    function nextImage():void {
       
        var thumb_url = BannerArray[my_playback_counter];
        var thumb_loader = new Loader();
        thumb_loader.load(new URLRequest(thumb_url));
        var my_image:Loader = Loader(thumb_loader);
        my_image_slides.addChild(my_image);
        my_tweens_array[0]=new Tween(my_image,"alpha",Strong.easeOut,0,1,1,true);
        //MovieClip(root).buttonArray[2].gotoAndStop(2);
        //"btn_"+ my_playback_counter.gotoAndStop(2);
       
       
    }

    function timerListener(e:TimerEvent):void {

        hidePrev();

        my_playback_counter++;
        if (my_playback_counter==my_total) {
            my_playback_counter=0;
           
        }
        nextImage();

    }

    function hidePrev():void {

        var my_image:Loader=Loader(my_image_slides.getChildAt(0));
        my_prev_tween=new Tween(my_image,"alpha",Strong.easeOut,1,0,1,true);
        my_prev_tween.addEventListener(TweenEvent.MOTION_FINISH, onFadeOut);
        //mc.buttonArray[my_playback_counter].gotoAndStop(1);
       

    }

    function onFadeOut(e:TweenEvent):void {
        my_image_slides.removeChildAt(0);
       
    }


    function mouseClickHandler(event:MouseEvent):void {
        var str:String = event.currentTarget.name;
        var i = str.substring(4,6);
        var thumb_url = BannerArray[i];
        var thumb_loader = new Loader();
        thumb_loader.load(new URLRequest(thumb_url));
        var my_image:Loader = Loader(thumb_loader);
        my_image_slides.addChild(my_image);
        my_tweens_array[0]=new Tween(my_image,"alpha",Strong.easeOut,0,1,1,true);
       
        my_timer.removeEventListener(TimerEvent.TIMER, timerListener);
        my_timer.addEventListener(TimerEvent.TIMER, timerListener);
        my_timer.start();
        my_playback_counter=i;
        event.currentTarget.gotoAndStop(2);
        trace(event.currentTarget.name);
    }


    }
    Last edited by letschillout; 10-27-2011 at 11:20 AM.
    Charag - 3D, Flash Games, Animations,
    Website Development & More...


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