-
Flash Genie
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...
-
Do not put the button names in the array, put the actual buttons in the array.
-
Flash Genie
-
Flash Genie
-
Flash Genie
btw i sorted out myself and these codes were very helpful
Actionscript Code:
/* convert array objects into movieclip */ for (var i:uint = 0; i < buttonArray.length ; i++) { var remov = buttonArray[i]; var ins:MovieClip = MovieClip(mc.getChildByName(remov)); ins.gotoAndStop(1); }
Actionscript Code:
/* detecting objects inside container or movieclip */ for (var i:uint = 0; i < mc.numChildren; i++){ trace (i+'.\t name:' + mc.getChildAt(i).name + '\t type:' + typeof (mc.getChildAt(i))+ '\t' + mc.getChildAt(i)); }
Charag - 3D, Flash Games, Animations,
Website Development & More...
-
If you had put the actual buttons in the array instead of their names, you wouldn't have had to set their names, and your code would be much simpler.
Code:
for (var i:uint = 0; i < buttonArray.length ; i++)
{
buttonArray[i].gotoAndStop(1);
}
Or even
Code:
buttonArray.forEach(function(obj:Object){MovieClip(obj).gotoAndStop(1);}, null);
As for your second bit of code, it doesn't seem to actually do anything except a trace. It's certainly not "detecting" anything as the comment says. What were you trying to accomplish?
And if it was just the trace, then save the result of the getChildAt call to a temporary variable so that you only have to execute it once rather than 3 times each time through the loop.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|