Показать сообщение отдельно
Старый 21.03.2011, 19:11
Weather вне форума Посмотреть профиль Отправить личное сообщение для Weather Посетить домашнюю страницу Weather Найти все сообщения от Weather
  № 1  
Ответить с цитированием
Weather

Регистрация: Mar 2006
Сообщений: 59
Отправить сообщение для Weather с помощью ICQ
По умолчанию Смена фоновой картинки пользователем!

Купил шаблончик в нем используется AS3, подскажите как устроить возможность выбора пользователем смену фоновой картинки?

Код прилагаю, все настройки в config файле

Код AS3:
//LOADING THE XML FILES NEEDED AND INITIALIZE THE VARIABLES WITH DATA FROM THE LOADED XML FILES
 
import gs.TweenMax;
import gs.easing.*;
 
var _bkW:Number;//the width of the background loaded image
var _bkH:Number;//the height of the background loaded image
var startX:Number = 10;//used to position the loader first time it show up
var _countdbs:int = 0;//used as a counter to check how many xml files are loaded
var _configUrlLoader:URLLoader;//used to load the config.xml file
var _videoUrlLoader:URLLoader;//used to load the xml file for the video player
var logoLoader:Loader;//used to load the logo 
var logoPath:String;//the path for the logo image
var bkImagePath:String;//the path for the background image
var contact_text:String;//the text for the contact window
var about_text:String;//the text for the about window
var videoLabel:String;//a string used to set the text for the video button
var aboutLabel:String;//a string used to set the text for the about button
var mainMenulabel:String;//a string used to set the text for the main button, the portfolio button
var contactLabel:String;//a string used to set the text for the contact button
var showContact:Boolean;//flag used to show or hide the contact button
var showabout:Boolean;//flag used to show or hide the about button
var showSoundIcon:Boolean;//flag used to show or hide the sound button
var showVideo:Boolean;//flag used to show or hide the video button
var configXML:XML;//this will be populated with the data from the loaded xml file the config.xml file
var _video_xml:XML;//this will be populated with the data from the loaded xml file, the video xml file
var _dbLoading_ar:Array;//used for loading xml files
var _submenuXMLPath_ar:Array;//holds all the paths for the galleries xml files
var _submenuLabel_ar:Array;//holds all the labels for the galleries xml files, this is used to set the text on the gallery buttons
var _submenusXML:Array;//holds all the galleries xml files
var _links_ar:Array;//this will hold all the properties of the external links buttons 
var totalSubmenus:int;//total number of galleries
var _bk_sp:Sprite;//this will hold the background loaded image
var _bkmasc_sp:Sprite;//this is used as a mask for _bk_sp
var _showSlideShowButton:Boolean;//this hides or shows the slide show button
var _showSlideDelay:Number;//the delay in seconds for the slide show
 
//Initialize this...
initLoader();
function initLoader():void {
	stop();
	//setting up the stage
	stage.align = StageAlign.TOP_LEFT;
	stage.scaleMode = StageScaleMode.NO_SCALE;
 
	//removing the categories MovieClips
	removeChild(full_mc);
	removeChild(small_mc);
	removeChild(about_mc);
	removeChild(contact_mc);
	removeChild(video_mc);
	addChild(_lupa_mc);
	addChild(_desc_mc);
	removeChild(next_mc);
	removeChild(prev_mc);
	removeChild(slideShow_mc);
 
	//setting up the buttons
	next_mc.mouseChildren = prev_mc.mouseChildren = slideShow_mc.mouseChildren = false;
	next_mc.buttonMode = prev_mc.buttonMode = slideShow_mc.buttonMode = true;
	_lupa_mc.mouseChildren = false;
	_lupa_mc.mouseEnabled = false;
	_desc_mc.alpha = 0;
 
	_loader_mc.visible = false;
	root.mouseChildren = false;
 
	loader_mc.txt_txt.text = "LOADING CONFIG XML" ;
	loader_mc.bk_mc.width = loader_mc.txt_txt.width +25;
	_bk_sp =  new Sprite();
	addChild(_bk_sp);
 
	//creating the mask for the background image
	_bkmasc_sp =  new Sprite();
	_bkmasc_sp.graphics.beginFill(0x00FF00,1);
	_bkmasc_sp.graphics.drawRect(0,0,10,10);
	_bkmasc_sp.graphics.endFill();
	addChild(_bkmasc_sp);
	_bk_sp.mask = _bkmasc_sp;
	setChildIndex(_bk_sp,0);
 
	//animate the loader
	loader_mc.x = -loader_mc.width;
	TweenMax.to(loader_mc,.6,{x:startX,ease:Quart.easeOut,onComplete:startToLoad});
}
 
//After the loader MovieClip is tweened load the config.xml file
function startToLoad():void {
	loadConfigXml();
}
 
//Loading the config xml file
function loadConfigXml():void {
	loader_mc.txt_txt.text = "LOADING CONFIG XML";
	loader_mc.bk_mc.width = loader_mc.txt_txt.width +25;
	_configUrlLoader = new URLLoader();
	_configUrlLoader.load(new URLRequest("config.xml"));
	_configUrlLoader.addEventListener(Event.COMPLETE,setupMenu);
}
 
//After the config.xml is loaded the variables are initialized based on the data from the loaded xml file
function setupMenu(e:Event):void{
	configXML =  new XML(e.target.data);
	totalSubmenus = configXML.main_menu.submenu.length();
	bkImagePath = configXML.bk_image_path;
	logoPath = configXML.logo_path;
	about_text = configXML.about_text;
	videoLabel = configXML.video_label;
	contact_text = configXML.contact_text;
	contactLabel = configXML.contact_us_label;
	aboutLabel = configXML.about_us_label;	
 
	if(configXML.show_about == "yes"){
		showAbout = true;
	}else{
		showAbout = false;
	}
	if(configXML.show_contact == "yes"){
		showContact = true;
	}else{
		showContact = false;
	}
 
	if(configXML.show_sound_icon == "yes"){
		showSoundIcon = true;
	}else{
		showSoundIcon = false;
	}
 
	if(configXML.show_video == "yes"){
		showVideo = true;
	}else{
		showVideo = false;
	}
 
	if(configXML.show_slide_show_icon == "yes"){
		_showSlideShowButton = true;
	}else{
		_showSlideShowButton = false;
	}
 
	if(isNaN(Number(configXML.slide_show_dealy))){
		_showSlideDelay = 1 * 1000;
	}else{
		_showSlideDelay = configXML.slide_show_dealy * 1000;
	}
 
	setupMainMenuAndSubenu();
	setupExternalLinks();
	loadVideoXML();
	root.dispatchEvent(new Event(Event.COMPLETE));
}
 
//Setting up the arrays for the menu
function setupMainMenuAndSubenu():void{
	mainMenulabel = configXML.main_menu.button_label;
	_submenuXMLPath_ar =  new Array();
    _submenuLabel_ar = new Array();
	_submenusXML =  new Array();
	_dbLoading_ar =  new Array();
	for(var i:int=0; i<totalSubmenus; i++){
		_submenuXMLPath_ar[i] = configXML.main_menu.submenu[i].main_path;
		_submenuLabel_ar[i] = configXML.main_menu.submenu[i].button_label;
	}
}
 
//Setting up the links array for the menu, this are the links buttons
function setupExternalLinks():void{
	_links_ar =  new Array();
	for(var i:uint=0; i<5; i++){
		var links_obj:Object =  new Object();
		links_obj.label = configXML.link[i].@label;
		links_obj.url = configXML.link[i].@url; 
		links_obj.target = configXML.link[i].@target;
		links_obj.show = configXML.link[i].@show;
		_links_ar.push(links_obj);
	}
}
 
//Load video xml
function loadVideoXML():void {
	_videoUrlLoader = new URLLoader();
	_videoUrlLoader.load(new URLRequest("load/video/load.xml"));
	_videoUrlLoader.addEventListener(Event.COMPLETE,videoLoadedComplete);
}
 
//When the video xml file has loaded, load the logo graphic
function videoLoadedComplete(e:Event):void {
	var _tempXML:XML =  new XML(e.target.data);
	_video_xml = new XML(_tempXML);
	loadLogo();
}
 
//Load the logo graphic
function loadLogo():void{
	logoLoader =  new Loader();
	logoLoader.load(new URLRequest(logoPath));
	logoLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,addLogo);
}
 
//When the logo graphics is loaded is added to logo_mc, the MovieClip container
function addLogo(e:Event):void{
	logo_mc.addChild(e.target.content);
	logo_mc.x = -logo_mc.width;
	menu_mc.y = logo_mc.y + logo_mc.height + 9;
	loadSubmenus();
}
 
//Loading the galleries xml files
function loadSubmenus():void {
	loader_mc.txt_txt.text = "LOADING XML FILES 1/" + totalSubmenus;
	loader_mc.bk_mc.width = loader_mc.txt_txt.width +25;
	var _ulrLoader:URLLoader = new URLLoader();
	_ulrLoader.load(new URLRequest(_submenuXMLPath_ar[_countdbs]));
	_ulrLoader.addEventListener(Event.COMPLETE,loadingXmlSubemuConplete);
}
 
//When a gallery xml file has loaded  the next one will load and when all of them are loaded, the loading of the background image will start
function loadingXmlSubemuConplete(e:Event):void {
	_countdbs ++;
	loader_mc.txt_txt.text = "LOADING XML FILES " + (_countdbs +1)  + "/" + totalSubmenus;
	var _tempXML:XML =  new XML(e.target.data);
	_submenusXML.push(_tempXML);
	if (_countdbs == totalSubmenus ) {
		loadBackgroundImage();
	}else{
		loadSubmenus();
	}
 
}