Wednesday, July 4, 2012

actionscript

PAGE EVENT

package com {
import flash.events.Event;
public class PageEvent extends Event {
public static const CHANGE_PAGE = "changePage";
public var vars:Object;
public function PageEvent( _type:String,
_vars:Object,
_bubbles:Boolean=false,
_cancelable:Boolean=false ) {
constructor code
super( _type, _bubbles, _cancelable); //refers to the parent class(Event)
vars = _vars; //{type:"up"}
}
public override function clone():Event {
return new PageEvent( type, vars, bubbles, cancelable );
}
}
}


MAIN

package com {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import com.PageEvent;
public class Main extends MovieClip {
var swfLoader:Loader = new Loader();
var aboutURL:URLRequest = new URLRequest('about_page.swf');
public function Main() {
this.btn_back.addEventListener(MouseEvent.CLICK, backClick);
this.btn_go_up.addEventListener(MouseEvent.CLICK, go_up_Click);
addEventListener (PageEvent.CHANGE_PAGE, doSomething);
}
private function doSomething(e:PageEvent){
trace("received CHANGE_PAGE");
trace(e.vars.eileen);
trace(e.vars.shiro);
}
private function backClick (e:MouseEvent){
this.btn_back.gotoAndPlay(2);
swfLoader.load(aboutURL);
swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, setupSwf)
}
private function setupSwf(e:Event){
this.pageholder.addChild(swfLoader);
var mc = swfLoader.content;

}

private function go_up_Click (e:MouseEvent){
this.y -= 50;
}
}
}


ABOUT

package com {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import com.PageEvent
public class About extends MovieClip {
public function About() {
this.btn_back_about.addEventListener(MouseEvent.CLICK, backClick_about);
this.btn_trigger.addEventListener(MouseEvent.CLICK,tellMain);
}
private function tellMain(e:MouseEvent){
trace("tell main to do something");
var evt = new PageEvent(PageEvent.CHANGE_PAGE, {eileen:"sleep", shiro:"faint"} ,true);
dispatchEvent (evt);
}
private function backClick_about (e:MouseEvent){
this.btn_back_about.gotoAndPlay(2);
}
}
}

No comments:

Post a Comment