A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [RESOLVED] Movie freezing upon page load

  1. #1
    Junior Member
    Join Date
    May 2006
    Location
    Cleveland, Ohio
    Posts
    11

    resolved [RESOLVED] Movie freezing upon page load

    Please help me understand this. I am working on a simple navigation right now, and I'm getting a strange behavior from it. The first time the page loads, everything works fine, the rollovers work and everything. But then, if I click one of the nav buttons to go to an inside page, and then go back either by using the Back button on the browser or clicking "Home" in the inside nav, the Flash nav on the home page freezes after a couple of seconds.

    I'm new to OOP here, so please be kind. The link to the project is: http://vocon.ext.aztekdev.com

    Here are my two classes.

    Main.as
    Code:
    package {
    	import flash.display.MovieClip;
    	import flash.display.Graphics;
    	import flash.events.*;
    	import Nav;
    	
    	public class Main extends MovieClip {
    		public function Main() {
    			
    			var sp:MovieClip = new MovieClip();
    			addChild(sp);
    			var g:Graphics = sp.graphics;
    			g.lineStyle(1,0xffffff);
    			g.moveTo(475,-260);
    			g.lineTo(475,780);
    			g.moveTo(-475,260);
    			g.lineTo(1425,260);
    			
    			var myMask:MovieClip = new MovieClip();
    			addChild(myMask);
    			var mg:Graphics = myMask.graphics;
    			mg.lineStyle(0);
    			mg.beginFill(0x000000,1);
    			mg.moveTo(10,0);
    			mg.lineTo(940,0);
    			mg.lineTo(940,520);
    			mg.lineTo(10,520);
    			mg.lineTo(10,0);
    			mg.endFill();
    			
    			sp.mask = myMask;
    			
    			this.addEventListener(Event.ENTER_FRAME,onLoop,false,0,true);
    			
    			function onLoop(evt:Event):void {
    				sp.x = mouseX-475;
    				sp.y = mouseY-260;
    			}
    			
    			var nav:MovieClip = new Nav();
    			addChild(nav);
    			nav.x = -140;
    		}
    	}
    }
    Nav.as
    Code:
    package {
    	import flash.display.MovieClip;
    	import flash.display.Graphics;
    	import flash.events.*;
    	import fl.transitions.*; 
    	import fl.transitions.easing.*;
    	import flash.net.*;
    	import NavButton;
    	
    	public class Nav extends MovieClip {
    		public function Nav() {
    			var urls:Array = new Array();
    			urls['button0'] = '/portfolio';
    			urls['button1'] = '/services';
    			urls['button2'] = '/culture';
    			urls['button3'] = '/news';
    			urls['button4'] = '/contact';
    			var btn:MovieClip;
    			var btnBg:MovieClip;
    			var btnMask:MovieClip;
    			for (var i:uint;i<5;i++) {
    				btn = new MovieClip();
    				btn.name = "button"+i;
    				btnBg = new NavButton();
    				btnBg.name = "buttonBg"+i;
    				btn.addChild(btnBg);
    				btnMask = new MovieClip();
    				btnMask.name = "buttonMask"+i;
    				addChild(btnMask);
    				var bg:Graphics = btnMask.graphics;
    				bg.lineStyle(0);
    				bg.beginFill(0x000000,1);
    				bg.moveTo(140,i*60);
    				bg.lineTo(300,i*60);
    				bg.lineTo(300,(i*60)+60);
    				bg.lineTo(140,(i*60)+60);
    				bg.lineTo(140,i*60);
    				bg.endFill();
    				btn.mask = btnMask;
    				btn.addEventListener(MouseEvent.MOUSE_OVER,onHover,false,0,true);
    				btn.addEventListener(MouseEvent.MOUSE_OUT,onOut,false,0,true);
    				btn.addEventListener(MouseEvent.CLICK,loadUrl,false,0,true);
    				btn.buttonMode = true;
    				addChild(btn);
    			}			
    			function onHover(evt:MouseEvent):void {
    				var tween:Tween = new Tween(evt.target,'x',Back.easeOut,0,150,.4,true);
    			}
    			
    			function onOut(evt:MouseEvent):void {
    				var tween:Tween = new Tween(evt.target,'x',Bounce.easeOut,150,0,.5,true);
    			}
    			
    			function loadUrl(evt:MouseEvent):void {
    				navigateToURL(new URLRequest(urls[evt.target.parent.name]),"_self");
    			}
    		}
    	}
    }

  2. #2
    Junior Member
    Join Date
    May 2006
    Location
    Cleveland, Ohio
    Posts
    11
    I figured it out for myself. I needed to move my event listeners out of the constructor functions.

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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center