Lively Kernel canvas
// this script is evaluated on world load
//itisnotserializeablebecausetheclasshastobetherebeforetheworldisloadedMorph.subclass('MyMorph',{initialize:function($super){//Morphareinitializedwithashape$super(newlively.scene.Rectangle(newRectangle(0,0,200,100)))this.applyStyle({borderWidth:1,borderColor:Color.black,fill:Color.green})},morphMenu:function($super,evt){varmenu=$super(evt);menu.addItem(["SayHello",function(){this.world().alert("Hi,Iam"+this.name)}],0)returnmenu}})//getridoftheoldinstancem=$morph('myTestMorph');if(m)m.remove()m=newMyMorph();m.openInWorld(pt(50,200))m.name='myTestMorph'25
Documentation:Classes40true
LivelyusesaClassbasedsystem.EverythingyouseeisaMorph.IfyouwanttocreatenewgraphicalobjectsyoucancreateasubclassofMorph.141
//gedridofallMyMorphsthis.world().submorphs.select(function(ea){returnea.constructor.name=='MyMorph'}).invoke('remove')2
toexectutetheworkspacebelow,presscmd+s(Mac)orCtrl+s(otherOS)
Thisclassdefinitionisnotpersistent.Soinstancesfromthatclasscannotbedeserializedproperly.Tomakethiswork,westoretheclass'MyMorph'inamodulesthatisloadedbythispage.Forthattoworkwechanged'localrequirements'propertywiththe'Localcodebrowser'to['documentation.MyModule'].143
Wikicontroltruetrue
null48