Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 3.0 (http://www.flasher.ru/forum/forumdisplay.php?f=83)
-   -   Смена фоновой картинки пользователем! (http://www.flasher.ru/forum/showthread.php?t=152694)

Weather 21.03.2011 19:11

Смена фоновой картинки пользователем!
 
Купил шаблончик в нем используется 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:Objectnew 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:XMLnew 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:XMLnew XML(e.target.data);
        _submenusXML.push(_tempXML);
        if (_countdbs == totalSubmenus ) {
                loadBackgroundImage();
        }else{
                loadSubmenus();
        }
 
}


Weather 21.03.2011 19:11

продолжение:

Код AS3:

//Loading the background image
function loadBackgroundImage():void {
        loader_mc.txt_txt.text = "LOADING BACKGROUND IMAGE 0%";
        var _loader:Loader = new Loader();
        _loader.load(new URLRequest(bkImagePath));
        _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,handleComplete);
        _loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,handleProgress);
        _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,handleIoError);
        function handleProgress(e:ProgressEvent):void {
                var percent:Number =  e.bytesLoaded/e.bytesTotal;
                loader_mc.txt_txt.text = "LOADING BACKGROUND IMAGE  " + Math.round(percent * 100) + "%";
                loader_mc.bk_mc.width = loader_mc.txt_txt.width +25;
        }
        function handleIoError(e:IOErrorEvent):void {
                throw new Error("THE BACKGROUND IMAGE PATH IS NOT CORECT!");
        }
 
        function handleComplete(e:Event) {
                var _bitmap:Bitmap = new Bitmap();
                _bitmap =  _loader.content;
                _bitmap.x = - _bitmap.width/2;
                _bitmap.y = - _bitmap.height/2;
                _bitmap.smoothing = true;
                _bk_sp.addChild(_bitmap);
                _bkW = _bitmap.width;
                _bkH = _bitmap.height;
                resizeAndPositionTheBkImg(_bk_sp,_bkW,_bkH,stage.stageWidth,stage.stageHeight);
                TweenMax.to(_bk_sp,.6,{alpha:1,ease:Quart.easeOut,overwrite:false,onComplete:clearLoader});
                TweenMax.to(_bkmasc_sp,.6,{width:stage.stageWidth,height:stage.stageHeight,overwrite:false,ease:Quart.easeOut});
                TweenMax.killTweensOf(loader_mc);
                TweenMax.to(loader_mc,.6,{x:-loader_mc.width,delay:.4,ease:Quart.easeOut,overwrite:false,onComplete:initSite});
                stage.addEventListener(Event.RESIZE,resizeBkImage);
                _loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,handleIoError);
                _loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS,handleProgress);
                _loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,handleComplete);
                _loader =  null;
        }
}
 
//Resize the background image and the background image mask
function resizeBkImage(e:Event):void {
        TweenMax.killTweensOf(_bkmasc_sp);
        _bkmasc_sp.width = stage.stageWidth;
        _bkmasc_sp.height = stage.stageHeight;
        resizeAndPositionTheBkImg(_bk_sp,_bkW,_bkH,stage.stageWidth,stage.stageHeight);
}
 
//When  the background image has loaded and it is visible remove the loader from stage
function clearLoader():void {
        removeChild(loader_mc);
}
 
//Function for rezing the background image
function resizeAndPositionTheBkImg(mc,W,H,contianerW,containerH) {
        var obj1 = new Object();
        var sW:Number = contianerW;
        var sH:Number = containerH;
        var baseScale:Number =  sW/W;//the scaling is made based on the stage w and the image w
        var sCx:Number = sW/W;
        var sCy:Number =  sH/H;
        if (baseScale < sCy) {
                baseScale = sCy;
        }
        var wD:Number = baseScale * W;
        var hT:Number = baseScale * H;
        var scX:Number = wD/W*1;//final scaleX
        var scY:Number = hT/H*1;//final scaleY
        mc.x = sW/2;
        mc.y = sH/2;
        mc.scaleX = scX;
        mc.scaleY = scY;
}


i.o. 21.03.2011 19:23

предлагаю обратиться в вакансии )

carrotoff 21.03.2011 20:41

думаю подобные моменты нужно было уточнить у продавца)

Weather 21.03.2011 20:51

тоесть ответа не будет? типа проще сослаться на надо было... или скорее всего...

i.o. 21.03.2011 21:00

Цитата:

тоесть ответа не будет? типа проще сослаться на надо было... или скорее всего...
Т.е. шансов, что найдется человек, который вам поможет решить это за бесплатно, очень мало.
Подождите еще денек, если не объявятся такие - делайте выводы.

NikolyA 21.03.2011 21:27

Weather ты пишешь: Купил шаблончик в нем используется AS3.

Встречный вопрос: ты понимаешь процесс работы данного шаблончика? может тебе все же послушать что говорит i.o. и заплатить еще немного денег чтоб тебе сделали


Часовой пояс GMT +4, время: 01:59.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.