A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Is it possible to have two navegation in the same .fla?

  1. #1
    Member
    Join Date
    Jan 2008
    Posts
    55

    Is it possible to have two navigation menus in the same .fla?

    I´m trying to have two navigations in the same scene where i want both to load external swf´s but i´m having problems with the 2nd one.

    I wrote this code in the first frame of my fla instead of writing it in the .as file. I don´t know if i´m doing well with this but i also tried to insert the same code in the .as but the same errors show up:

    Code:
    private var _swfPathArr:Array = new Array("swfs/AugmentedReality_v1.swf", "swfs/Contactos.swf", "swfs/Eventos.swf","swfs/Fotos.swf","swfs/Medium.swf","swfs/Texto.swf","swfs/Video.swf");
            private var _loadedSWFs:int;
            private var _swfClipsArr:Array = new Array();
            private var _swfTempClip:MovieClip;
    
    
    startLoading(_swfPathArr);
     
    function startLoading(pathArr:Array):void {
        _swfLoader = new Loader();
        _swfRequest = new URLRequest();
       
        loadSWF(pathArr[0]);
    }
     
    function loadSWF(path:String):void {
        setupListeners(_swfLoader.contentLoaderInfo);
       
        _swfRequest.url = path;
        _swfLoader.load(_swfRequest);
    }
     
    function setupListeners(dispatcher:IEventDispatcher):void {
        dispatcher.addEventListener(Event.COMPLETE, onSwfComplete);
        dispatcher.addEventListener(ProgressEvent.PROGRESS, currentSwfProgress);
    }
     
    function currentSwfProgress(event:ProgressEvent):void {
        var _perc:int = (event.bytesLoaded / event.bytesTotal) * 100;
        // swfPreloader.percentTF.text = _perc + "%";
    }
    
    function onSwfComplete(event:Event):void {
        event.target.removeEventListener(Event.COMPLETE, onSwfComplete);
        event.target.removeEventListener(ProgressEvent.PROGRESS, currentSwfProgress);
     
        _swfTempClip = event.target.content;
        _swfTempClip.customID = _loadedSWF;
     
        _swfClipsArr.push(_swfTempClip);
       
        if(_loadedSWFs <_swfPathArr.length - 1) {
            _loadedSWFs++;
            loadSWF(_swfPathArr[_loadedSWFs]);
        } else {
            onCompletePreloading();
        }
    }
    
    function onCompletePreloading():void {
        contentContainer.addChild(_swfClipsArr[0]);
       
        btn1.addEventListener(MouseEvent.CLICK, setContent);
        btn2.addEventListener(MouseEvent.CLICK, setContent);
        btn3.addEventListener(MouseEvent.CLICK, setContent);
    	btn4.addEventListener(MouseEvent.CLICK, setContent);
        btn5.addEventListener(MouseEvent.CLICK, setContent);
        btn6.addEventListener(MouseEvent.CLICK, setContent);
    	btn7.addEventListener(MouseEvent.CLICK, setContent);
    	
    }
     
    function setContent(event:MouseEvent):void {
        var _swfToAdd:MovieClip;
       
        switch(event.target.name) {
            case "btn1":
            _swfToAdd = _swfClipsArr[0];
            break;
           
            case "btn2":
            _swfToAdd = _swfClipsArr[1];
            break;
           
            case "btn3":
            _swfToAdd = _swfClipsArr[2];
            break;
    		
    		case "btn4":
            _swfToAdd = _swfClipsArr[3];
            break;
    		
    		case "btn5":
            _swfToAdd = _swfClipsArr[4];
            break;
    		
    		case "btn6":
            _swfToAdd = _swfClipsArr[5];
            break;
    		
    		case "btn7":
            _swfToAdd = _swfClipsArr[6];
            break;
        }
       
        contentContainer.removeChildAt(contentContainer.numChildren-1);
        contentContainer.addChild(_swfToAdd);
        trace(_swfToAdd.customID);
    }
    But i get a few errors:

    Scene 1, Layer 'script_menu', Frame 1, Line 10 1120: Access of undefined property _swfLoader.
    Scene 1, Layer 'script_menu', Frame 1, Line 11 1120: Access of undefined property _swfRequest.
    Scene 1, Layer 'script_menu', Frame 1, Line 17 1120: Access of undefined property _swfLoader.
    Why doesn´t he identify these three properties?

    Thanks for the help.
    Last edited by FabM; 08-02-2010 at 05:58 AM.

  2. #2
    Member
    Join Date
    Jan 2008
    Posts
    55
    I´ve created a new movieclip for the other menu and tried to code it in the general .as class while trying to duplicate the functions for the other menu.

    Let´s forget about the code i`ve posted.

    I gave it an instance name of cont4 for the menu and changed the code to receive it:

    Code:
    package {
    	
        import com.greensock.TweenLite;
        import com.greensock.TweenMax;
        import com.greensock.*;
        import com.greensock.easing.*;
        import flash.display.*;
    	import flash.events.*;
    	import flash.display.MovieClip;
    	import fl.transitions.*;
        import fl.transitions.easing.*;
    	import flash.net.URLRequest;
        import flash.display.Loader;
        import flash.events.Event;
        import flash.events.ProgressEvent;
        import flash.net.NetStream;
         
    	
    
    	
    	public class Painel3 extends MovieClip
    	
    	{
    	private var inFocus:MovieClip;
    	private var files:Array;
            private var swf:Loader;
    		
    		
    		public function Painel3():void
    		{
    			 files = ["AugmentedReality_v1","Texto","Fotos","Video","Contactos","Eventos","Medium"];
                if (stage) init();
                else addEventListener(Event.ADDED_TO_STAGE,init);
    			}
    			
    	    private function init (e:Event = null):void {
                removeEventListener(Event.ADDED_TO_STAGE,init);
                setupClips();
                stage.addEventListener(MouseEvent.MOUSE_MOVE,onMove);
            }
    
    		
    		private function setupClips():void
    		{  
    			var len:int = cont3.numChildren;
    			var len:int = cont4.numChildren;
    			
    			
    			for(var i:int=0; i<len; i++)
    			{
    				var mc:MovieClip = MovieClip(cont3.getChildAt(i));
    				var mc:MovieClip = MovieClip(cont4.getChildAt(i));
    				
    				mc.buttonMode = true;
    				mc.loc = [mc.x, mc.y];
    				mc.id = i;
    				mc.addEventListener(MouseEvent.CLICK, onClick);
    			}
    			
    	    down.buttonMode = true;
                down.addEventListener(MouseEvent.CLICK,goTo);
                removeChild(down);
    					}
    								
    								
    		 
    		private function onClick(e:MouseEvent):void
    		{
    	    var index:int = e.currentTarget.id;
                var ldr:Loader = new Loader();
                ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgress);
                ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
                ldr.load(new URLRequest("swfs/" + files[index] + ".swf"));
    }
    	    private function onProgress(e:ProgressEvent):void {
                var percent:Number = e.bytesLoaded/e.bytesTotal * 100;
                trace(percent);
            }
    
            
    private function onComplete(e:Event):void {
                var info:LoaderInfo = e.target as LoaderInfo;
                info.removeEventListener(ProgressEvent.PROGRESS,onProgress);
                info.removeEventListener(Event.COMPLETE,onComplete);
                swf = info.loader;
                swf.x = 140;
                swf.y = 100;
                stage.removeEventListener(MouseEvent.MOUSE_MOVE,onMove);
                removeChild(cont3);
    	    removeChild(cont4);
                addChild(swf);
                addChild(down);
               TransitionManager.start(down, {type:Fade, direction:Transition.IN, duration:5, easing:Strong.easeOut});
    
            }
    
    private function goTo(e:MouseEvent):void {
                if (swf && swf.parent) {
                    removeChild(swf);
                    swf = null;
                }
                removeChild(down);
                addChild(cont3);
    	    addChild(cont4);
                stage.addEventListener(MouseEvent.MOUSE_MOVE,onMove);
            }
    
    		
    		
    		
    		private function onMove(e:Event):void
    		{
    			var distx:Number = mouseX / 1650;
    			var disty:Number = mouseY / 1450;
    			TweenLite.to(cont3, 2, { 
    						rotationY:(-70 +(145*distx)), 
    						
    						ease:Expo.easeOut 
    						 });
    		}
    	}
    }
    The problem is that i got two 3596 errors because of two duplicate variable definitions and i don´t know how can i setup the other menu to work using this code.

    Please help me put with this. Thanks.

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