linking library class to an extended class and baseclass
The use of library classes confuses me once again. I have the following situation:
package com.op_pad.pages
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
/**
* ...
* @author Martino Wullems
*/
public class Page extends MovieClip
{
public var currentPage:String = ""; //help page label
public var testvar:int = 0;
var helpPage:HelpPage;
public function Page(PAGENAME:String = null):void {
//tweening etc
addEventListener(Event.ADDED_TO_STAGE, onStage);
trace("currentPage: " + currentPage);
trace("testvar: " + testvar);
}
private function onStage(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, onStage);
trace("on stgae called");
try { terug.addEventListener(MouseEvent.CLICK, goback, false, null, true) } catch (e) { };
try{homebutton.addEventListener(MouseEvent.CLICK, goHome, false, 0, true)}catch (e) { };
try { stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown, false, 0, true) } catch (e) { trace("back button fail"); };
try { help.addEventListener(MouseEvent.CLICK, showHelpPage, false, 0, true) } catch (e) { trace("help not found") };
}
public function addListeners():void {
//try{terug.addEventListener(MouseEvent.CLICK, goback, false, null, true)}catch(e){};
//try{homebutton.addEventListener(MouseEvent.CLICK, goHome, false, 0, true)}catch (e) { };
//try{stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown, false, 0, true)}catch (e) {trace("back button fail"); };
}
public function goback(e:MouseEvent):void
{
try { MovieClip(parent).loading = false } catch (e) { trace("loading boolean not existent");}
MovieClip(parent).removeChild(this);
}
private function goHome(e:MouseEvent):void
{
try { MovieClip(parent).loading = false } catch (e) { trace("loading boolean not existent");}
MovieClip(parent).removeChild(this);
}
private function show开发者_StackOverflow社区HelpPage(e:MouseEvent):void
{
helpPage = new HelpPage();
addChild(helpPage);
helpPage.gotoAndStop(currentPage);
trace("help page called, currentPage: " + currentPage);
}
private function onKeyDown(e:KeyboardEvent):void
{
//when keyboard back is pressed
if (e.keyCode == Keyboard.BACK) {
e.preventDefault();
e.stopImmediatePropagation();
goback(null);
}
}
}
}
Sloppy code, still needs cleaning up.
A child class that inherits the Page class
package
{
import com.op_pad.pages.Page;
/**
* ...
* @author Martino Wullems
*/
public class FavorietenPage extends Page
{
public function FavorietenPage():void
{
trace("favorietenpage called");
super();
currentPage = "favorieten";
}
}
}
"FavorietenPage" is also a library item that I want to add to the stage. I have tried several setups but cannot get it to work.
Most logical to me seems the following [library item properties]: Class: com.op_pad.pages.FavorietenPage BaseClass: com.op_pad.pages.Page;
I cannot put in any baseclass when using the class, so I'm forced to remove the baseclass. When using only the class I get a whole bunch of errors don't make any sense at all, and still appear even if I comment out all the code in the Page class.
com\op_pad\pages\FavorietenPage.as:7: 1152: A conflict exists with inherited definition com.op_pad.pages:Page.help in namespace public.
com\op_pad\pages\FavorietenPage.as:12: 1152: A conflict exists with inherited definition com.op_pad.pages:Page.terug in namespace public.
com\op_pad\pages\FavorietenPage.as:21: 1152: A conflict exists with inherited definition com.op_pad.pages:Page.home in namespace public.
This doesn't make any sense to me at all. Any idea how this situation should be used?Thanks in advance
You have misunderstood the meaning of the "class" and "base class" fields in the properties panel:
The value of the Base Class defaults to
flash.display.MovieClip
. Use this default unless you are using an automatically generated class that uses the functionality of an external class. Base Class is not synonomous with extension; if you are specifying a custom class that itself extends another class, it is not necessary to specify this superclass as the Base Class. In this situation, the default offlash.display.MovieClip
is sufficient. If, however, you wanted two symbols, RedFish and BlueFish, to function identically but have different skins, you could use the authoring tool to create different appearances, then set their Base Class to Fish and use a Fish class in an external Fish.as file to provide the functionality for both fish.
(from the Adobe Developer Connection)
精彩评论