Author Topic: External Class  (Read 1780 times)

Zaqoa

  • Newbie
  • *
  • Posts: 2
External Class
« on: December 01, 2009, 03:01:30 pm »
Add some custom class loading to the mag...

first add some node-type to the xml called class
 <class src='name.swf' name=dir.classname' param='param1,param2,paramX' />

change the page.as objects:
INTERNAL_ELEMENTS:Array = new Array("area", "img", "nav", "snd", "txt", "class");
INTERNAL_CLASSES:Array = new Array(Area, Image, Navigation, Audio, Text, ExternalClass);

add some lines to the megazine parser
var classID:String = (pageData[id] as XML).children()[0].toXMLString();
if (StringUtils.contains(classID, "<class"))
{
   var param:Array = Delimiter.parseComma((pageData[id] as XML).children()[0].@param.toXMLString());
   dataProvider[param[0]] = param;
}

The Delimiter class separates the param-attribute into an array.
The dataProvider is a simple array, as a private property from the megazine class

define another AbstractElement called ExternalClass
load the src from the class-node
if (xml.@name.toString() != "") { classname = xml.@name.toString(); }
classLoader.load(url, false);

and init the class after loading.
classLoader.removeEventListener(ClassLoader.CLASS_LOADED, onEvent);
classItem = classLoader.getClass(classname);
var id:int = page.getNumber(even) + 1;
var obj:* = new classItem();
obj.init(mz.dataProvider[id], false);
obj.setCallback(mz.callback);

Note that every external class loading container implements an interface called IPage
function init(data:Array, logstatus:Boolean):void;
function getData():Array;
function setCallback(callback:Function):void;   

that's it...

the forum is not the best for publishing code...
if you interested, i send you the customized code snippets...


Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: External Class
« Reply #1 on: December 01, 2009, 09:28:54 pm »
I don't really understand what that does, could you explain? It looks a bit like a roundabout way to a functionality similar to what's possible using external elements (e.g. vid).
For the Snark was a Boojum, you see.

Before you ask a question
          After you get an answer
  • please document your problem with the answer in the Project Wiki. (e.g. in the FAQs)
  • help others out if you can, by answering their questions on the forum.

Zaqoa

  • Newbie
  • *
  • Posts: 2
Re: External Class
« Reply #2 on: December 09, 2009, 10:11:41 am »
The Snippet allow you to load custom classes with custom properties and give you the possibility to call other functions from these classes with the callback function.

e.g. you have a time-controlled book, where at specific points some pages are enabled and disabled ... and the pages call an external flash layer with some video stuff ...