For most things, you can just use EaselsJS and SoundJS docs. Read below about NanoFL-specified features.
Important rules:
- Most time you don't need to use
cache()
method: if your object have none emptyfilters
then NanoFL cache it automatically. - If you need to uncache your object, don't forget to uncache dependent objects too (often this are the parent objects).
You can use
nanofl.DisplayObjectTools.smartUncache(myObj)
for this. - In most cases you don't need to create instances of
Bitmap
/Button
/MovieClip
directly. Use generated children classes in src folder for that.
NanoFL classes:
- Bitmap - represent Bitmap Symbol on the canvas.
- Button - represent MovieClip Symbol with a button behavior (checked "Treat as button").
- DisplayObjectTools - helpers applicable to
createjs.DisplayObject
. - MovieClip - represent MovieClip Symbol (EaselJS's MovieClip class does not used by NanoFL).
- Player - global store for CreateJS's stage and NanoFL's library and scene.
- SeamlessSoundLoop - helper to play background music without gaps.
- TextField - represent static and dynamic text on the canvas.
- TextRun - represent a formatted piece of text for
TextField
.
Extends createjs.Bitmap. Just image on canvas. Example:
var bmp = new nanofl.Bitmap(nanofl.Player.library.getItem("myBitmap"));
container.addChild(bmp);
Extends nanofl.MovieClip. Movie clip with 4 frames: regular, mouse over, ouse pressed and hit area. Example:
var btn = new nanofl.Button(nanofl.Player.library.getItem("myButton"));
container.addChild(btn);
Helper methods applicable to createjs.DisplayObject
.
smartCache(myObj:DiplayObject)
- cache objects in the tree (depend on filters and masks). In most cases NanoFL cache objects automatically.smartUncache(myObj:DiplayObject)
- uncachemyObj
display object and dependent objects (depend on masks). In most cases NanoFL uncache objects automatically.getOuterBounds(myObj:DiplayObject)
- returns object bounds include filters bounds (invariant to cache).getInnerBounds(myObj:DiplayObject)
- returns object bounds exclude filters bounds (invariant to cache).dump(myObj:DiplayObject)
- trace objects tree.
Examples:
nanofl.DisplayObjectTools.smartCache(myMovieClip);
nanofl.DisplayObjectTools.smartUncache(myMovieClip);
var bounds = nanofl.DisplayObjectTools.getOuterBounds(myMovieClip);
var bounds = nanofl.DisplayObjectTools.getInnerBounds(myMovieClip);
nanofl.DisplayObjectTools.dump(myMovieClip);
Extends createjs.Container
This is a special container to store layer-related children
(automatically when constructed from library symbol).
Also can contain children not related to any layer (so you can call addChild()
to add your DisplayObject
to MovieClip
).
Example:
var mc = new nanofl.MovieClip(nanofl.Player.library.getItem("myMovieClip"));
container.addChild(mc);
paused
- a boolean to specify not to advance to the next frame on tickloop
- a boolean to specify go to the first frame on movie is finishedcurrentFrame
- readonly integer which represent current frame index (zero-based)
play()
- setpaused
to falsestop()
- setpaused
to truegotoAndStop(labelOrIndex)
- go to specified frame and stopgotoAndPlay(labelOrIndex
) - go to specified frame and playgetTotalFrames()
- returns most long layer lengthonEnterFrame()
- override this method for your needsonMouseDown(e:createjs.MouseEvent)
- override this method for your needsonMouseMove(e:createjs.MouseEvent)
- override this method for your needsonMouseUp(e:createjs.MouseEvent)
- override this method for your needs
This class is accessible anywhere. Use it to control global properties.
library
- a object with agetItem(namePath)
method; use this method to get symbols from librarystage
- a createjs.Stage object (use to customize native CreateJS stage)scene
- a nanofl.MovieClip scene object (root movie clip)
Use this class for gapless background music loops. Example:
var music = new nanofl.SeamlessSoundLoop(createjs.Sound.play("mySound"));
...
music.stop();
new(sound:createjs.AbstractSoundInstance)
- constructorstop()
- stop playing (create new object to start again)
This class represent a multi-line and multi-format text on canvas. Example:
var tf = new nanofl.TextField();
tf.text = "My text";
border
- set totrue
to show black border around text fieldheight
- current height of text fieldminHeight
- minimal height calculated on text; readonlyminWidth
- minimal width calculated on text; readonlytext
- allow get or set whole text as a stringtextRuns
- array of TextRun which contains field's text blockswidth
- current width of text field
new()
- constructor
This class represent a piece of text and it's format. Used in TextField to store text blocks.
align
- a string ("left", "right", "center" or "justify")characters
- text stringfamily
- font family (like "Courier New")fillColor
- fill color ("red", "#ff0000", "rgba(255, 0, 0, 0.5)")kerning
- a boolean to do auto kerningletterSpacing
- space between letters (ignored if kerning is on)lineSpacing
- additional space between linessize
- font sizestrokeColor
- stroke color (used only if strokeSize > 0)strokeSize
- stroke thickness (zero for regular text)style
- font style ("", "bold", "italic" or "bold italic")
new([characters], [fillColor], [size])
- constructorclone()
- returns a copy of this object