import com.greensock.TweenLite; var xmlURL:String="theme.xml"; var xml:XML; var len:int; var arr_themeID:Array; var arr_themeName:Array; var arr_themeImageURL:Array; var arr_themeRemark:Array; var distance:Number=5; var counter:int=1; var arr_selectedTheme:Array=[]; var themeSprite:Sprite=new Sprite(); addChild(themeSprite); themeSprite.x=20; themeSprite.y=50; setChildIndex(cmHelp,getChildIndex(themeSprite)); setChildIndex(themePicture,getChildIndex(themeSprite)-1); var mask_themeSprite:Sprite=new Sprite(); mask_themeSprite.graphics.beginFill(0xffcccc); mask_themeSprite.graphics.drawRect(15,50,580,390); mask_themeSprite.graphics.endFill(); //addChild(mask_themeSprite); themeSprite.mask=mask_themeSprite; var mask_themePicture:Sprite=new Sprite(); mask_themePicture.graphics.beginFill(0x000000); mask_themePicture.graphics.drawRect(15,50,580,390); mask_themePicture.graphics.endFill(); //addChild(mask_themePicture); themePicture.mask=mask_themePicture; //------------------------------------------------------------------------------------------------------------- loadXML(xmlURL); function loadXML(url):void { var xmlLoader:URLLoader=new URLLoader(); xmlLoader.load(new URLRequest(url)); xmlLoader.addEventListener(Event.COMPLETE,xmlLoadedHandler,false,0,true); } function xmlLoadedHandler(e:Event):void { xml=XML(e.currentTarget.data); len=xml.BusinessInfo.length(); arr_themeID=[]; arr_themeName=[]; arr_themeImageURL=[]; arr_themeRemark=[]; for (var i:int=0; i<len; i++) { var _themeID=xml.BusinessInfo[i].ID; var _themeName=xml.BusinessInfo[i].Name; var _themeImageURL=xml.BusinessInfo[i].Image; var _themeRemark=xml.BusinessInfo[i].Remark; arr_themeID[i]=_themeID; arr_themeName[i]=_themeName; arr_themeImageURL[i]=_themeImageURL; arr_themeRemark[i]=_themeRemark; } loadThemeModule(1); pageFirst.addEventListener(MouseEvent.CLICK,pageFirstClickedHandler,false,0,true); pagePrev.addEventListener(MouseEvent.CLICK,pagePrevClickedHandler,false,0,true); pageNext.addEventListener(MouseEvent.CLICK,pageNextClickedHandler,false,0,true); pageLast.addEventListener(MouseEvent.CLICK,pageLastClickedHandler,false,0,true); //btnDownLoad.addEventListener(MouseEvent.CLICK,btnDownLoadClickedHandler,false,0,true); cmHelp.addEventListener(MouseEvent.CLICK,cmHelpClickedHandler,false,0,true); //cmHelp.closeBtn.addEventListener(MouseEvent.CLICK,closeBtnClicked,false,0,true); } //------------------------------------------------------------------------------------------------------------- function loadThemeModule(partIndex:int):void { var columnNum:int=2; var columnIndex:int; var rowIndex:int; var startIndex:int; var endIndex:int; if (partIndex==Math.ceil(len/6)&&len%6!=0) { startIndex=Math.floor(len/6)*6; endIndex=len; } else { startIndex=partIndex*6-6; endIndex=partIndex*6; } for (var j:int=startIndex; j<endIndex; j++) { var themeModule:ThemeModule=new ThemeModule(arr_themeID[j],arr_themeName[j],arr_themeImageURL[j],arr_themeRemark[j]); themeModule.name=String(j); themeSprite.addChild(themeModule); themeModule.mouseArea.buttonMode=true; if (arr_selectedTheme.indexOf(arr_themeName[j]+" ")>=0) { trace("该页含有之前已选中的themeModule !"); themeModule.Selected=true; themeModule.judgeSelected(); } columnIndex++; if (j%columnNum==0) { rowIndex++; columnIndex=0; } themeModule.x=(themeModule.width+distance)*columnIndex; themeModule.y=distance+(themeModule.height+distance)*(rowIndex-1); themeModule.addEventListener(ThemeModule.CLICKED,themeClickedHandler,false,0,true); //themeModule.addEventListener(ThemeModule._DESELECTED,themeCancelHandler,false,0,true); } } //------------------------------------------------------------------------------------------------------------- function themeClickedHandler(e:Event):void { var theme:ThemeModule=e.currentTarget as ThemeModule; var index:int=int(theme.name); if (theme.Selected==true) { if (arr_selectedTheme.indexOf(arr_themeName[index]+" ")==-1&&arr_selectedTheme.length<5) { arr_selectedTheme.push(arr_themeName[index]+" "); tf_themeSelected.text=arr_selectedTheme.toString(); trace("themeModule "+(index+1)+" is"+" selected!"); } } else { for (var k1:int=arr_selectedTheme.length-1; k1>=0; k1--) { if (arr_selectedTheme[k1]==arr_themeName[index]+" ") { arr_selectedTheme.splice(k1,1); } } tf_themeSelected.text=arr_selectedTheme.toString(); trace("themeModule "+(index+1)+" is"+" cancel!"); } } //------------------------------------------------------------------------------------------------------------- function pageFirstClickedHandler(e:MouseEvent):void { if (counter--==1) { counter=1; return; } counter=1; removeMC(); loadThemeModule(counter); themePicture.y=55; themeSprite.y=-330; TweenLite.to(themePicture,0.7,{alpha:0,y:435}); TweenLite.to(themeSprite,0.7,{y:50}); themePicture.alpha=1; } function pagePrevClickedHandler(e:MouseEvent):void { counter--; if (counter==0) { counter=1; return; } removeMC(); loadThemeModule(counter); themePicture.y=55; themeSprite.y=-330; TweenLite.to(themePicture,0.7,{alpha:0,y:435}); TweenLite.to(themeSprite,0.7,{y:50}); themePicture.alpha=1; } function pageNextClickedHandler(e:MouseEvent):void { counter++; if (counter==Math.ceil(len/6)+1) { counter=Math.ceil(len/6); return; } removeMC(); loadThemeModule(counter); themePicture.y=55; themeSprite.y=435; TweenLite.to(themePicture,0.7,{alpha:0,y:-325}); TweenLite.to(themeSprite,0.7,{y:50}); themePicture.alpha=1; } function pageLastClickedHandler(e:MouseEvent):void { if (counter++==Math.ceil(len/6)) { counter=Math.ceil(len/6); return; } counter=Math.ceil(len/6); removeMC(); loadThemeModule(Math.ceil(len/6)); themePicture.y=55; themeSprite.y=435; TweenLite.to(themePicture,0.7,{alpha:0,y:-325}); TweenLite.to(themeSprite,0.7,{y:50}); themePicture.alpha=1; } function cmHelpClickedHandler(e:MouseEvent):void { cmHelp.gotoAndPlay(2); } function closeBtnClicked():void { cmHelp.gotoAndPlay(207); } //------------------------------------------------------------------------------------------------------------- function removeMC():void { var num:int=themeSprite.numChildren; for (var k:int=0; k<num; k++) { themeSprite.removeChildAt(0); } } package { import flash.display.Sprite; import fl.controls.CheckBox; import flash.text.TextField; import flash.display.Loader; import flash.net.URLRequest; import flash.events.Event; import flash.events.MouseEvent; public class ThemeModule extends Sprite { public var Selected:Boolean; private var checkBox:CheckBox; public static const CLICKED:String="clicked"; public static const ERROR_DISPLAY:String="error_display"; public var themeID:int; private var confinedWidth:Number=100; private var confinedHeight:Number=100; private var image:Loader; public function ThemeModule(_id:int,_themeName:String,_imageURL:String,_themeRemark:String):void { checkBox=new CheckBox() ; addChild(checkBox); checkBox.x=170; checkBox.y=6; checkBox.addEventListener(Event.CHANGE,checkBoxChanged,false,0,true); mouseArea.addEventListener(MouseEvent.CLICK,mouseAreaClickedHandler,false,0,true); themeID=_id; tf_themeName.text=_themeName; tf_themeRemark.text=_themeRemark; loadImage(_imageURL); } //------------------------------------------------------------------------------------------------------------- private function loadImage(url:String):void { var imageLoader:Loader=new Loader(); addChild(imageLoader); imageLoader.load(new URLRequest(url)); imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,imageLoadedHandler,false,0,true); } private function imageLoadedHandler(e:Event):void { image=e.currentTarget.loader; image.x=5; image.y=5; setImageSize(); } private function setImageSize():void { if (image.width<=confinedWidth&&image.height<=confinedHeight) { //不需要执行任何图片变形操作 } else { if (image.width/confinedWidth>=image.height/confinedHeight) { image.width=confinedWidth; image.height=confinedWidth/image.width*image.height; } else { image.height=confinedHeight; image.width=confinedHeight/image.height*image.width; } } } //------------------------------------------------------------------------------------------------------------- private function checkBoxChanged(e:Event):void { var _checkBox:CheckBox=e.currentTarget as CheckBox; if (_checkBox.selected==true) { Selected=true; } else { Selected=false; } judgeSelected(); } private function mouseAreaClickedHandler(e:MouseEvent):void { if (rectBg.currentFrame==1) { Selected=true; } else { Selected=false; } judgeSelected(); } public function judgeSelected():void { if (Selected==true) { rectBg.gotoAndStop(2); checkBox.selected=true; if (Statistic.COUNTER==5) { dispatchEvent(new Event(ERROR_DISPLAY)); } } else { rectBg.gotoAndStop(1); checkBox.selected=false; } dispatchEvent(new Event(CLICKED)); } } } package { public class Statistic { public static var COUNTER:Number; public function Statistic():void { trace("Statistic.as is created !"); } } }