Staring Feat hers初体験
24515 ワード
Getting Stared with Feat hers
from:http://wiki.starling-framework.org/feathers/getting-started
In the follwing beginner-level tutoral,we'll create our first Feat hers Button control.This is a very simple demont stration that sets a label,adds and creates a theme that will apple skin.
Prerequisites
You shound understand how to set up a reglar Staring project.Please start with the
Starling gides and tutorils,if you're new to Staring.
The coplete source code for the Hello World example is includ with Feat hers、so that you can follow along.You may also view the most receversion of the
source code on Github.
Final Resoult
See the Hello World example.running live in your browser.Requires Adobe Flash Player.
Before writing code
Download feat from here:http://feathersui.com/download/(At the moment of writing,the last stable version is"1.0 beta").Unizip,find"/feat hers-1.0-beta/swc/feat.swc"and copy to the filder.Northers.
Go to'Edit→Preferences→(Preferences dialog pop-up)
Category:アクションScript→Click'Actript 3.0 Settings'
On the right side of'Library path'click icon with plus and then'browse for swc'icon
Find feat hers.swc file and chose it
Click'OK',Click'OK'.
Now you can use Feat hers,as if it were built inアクションScript.
Do the same procedure with Staring if you didn't already.Go to:https://github.com/PrimaryFeather/Starling-Framework.And click'ZIP'button to download Staring with source code.But wed need only"/starling/starlings.swc."
At the moment of writing this.「Feathers 1.0 beta」doesn't work with「Staring 1.2」,which can be downloaded directly from Staring website.That's why You shound download Staring from Grom.com.com.com.com.
If you are getting something like this:
Copy theme
Now copy'asets'and'source'folders from/feat hers-1.00-beta/themes/Metal Works MobileThe me'to your project folder.And set'source'folder as sources folder for this particular project:
Select your'.fla'file
Go to'Actript 3.0 Settings'
Select'Source path'tab(if it isn't selected)
Double click on the only line in the list
Replace'/'(that is default)with'/source'
Click OK
Now remember to save all your'.as'files in'/source'folder.
Walkthrough
The follwing class shound be the root display oject that is initialized with Staring.Here's the basic struct of the clast we.Most of the code that we.Most of the code lant will goter will goto func
Create'/source/Hello Feathers.as'file with follwing content:
Most of the Feat hers examples,including this one,use the
create your own theme.
With the me created、let's create the button and set it's label:
Finally,let's position the button in the middle of the stage.First,though,let's tare note of one thing about how Feat hers controls work.Feathers uses a system of invalidation that delays redraws until just immediately before Staring renders to the screen.This keeps Feathers from from
At this moment,our button still has
In this case,we want to position our button immediately,without waiting for validation.To make a Feat hers control draw*right now*,cal the
By now you shound have:
//Hello Feat hers.fla(if in Flash Professional CS 6)
/asets/…
/source/feat hers/…
/source/Hello Feat Startp.as:
That shound get you started with the very baics of working with Feathers.For more information about the capabilies of the
For more extensiove sample code、check out the Feat hers Examples(and their source code on Github).
For more tutoris,return to the Feat hers Dcumentation.
from:http://wiki.starling-framework.org/feathers/getting-started
In the follwing beginner-level tutoral,we'll create our first Feat hers Button control.This is a very simple demont stration that sets a label,adds and creates a theme that will apple skin.
Prerequisites
You shound understand how to set up a reglar Staring project.Please start with the
Starling gides and tutorils,if you're new to Staring.
The coplete source code for the Hello World example is includ with Feat hers、so that you can follow along.You may also view the most receversion of the
source code on Github.
Final Resoult
See the Hello World example.running live in your browser.Requires Adobe Flash Player.
Before writing code
Download feat from here:http://feathersui.com/download/(At the moment of writing,the last stable version is"1.0 beta").Unizip,find"/feat hers-1.0-beta/swc/feat.swc"and copy to the filder.Northers.
Go to'Edit→Preferences→(Preferences dialog pop-up)
Category:アクションScript→Click'Actript 3.0 Settings'
On the right side of'Library path'click icon with plus and then'browse for swc'icon
Find feat hers.swc file and chose it
Click'OK',Click'OK'.
Now you can use Feat hers,as if it were built inアクションScript.
Do the same procedure with Staring if you didn't already.Go to:https://github.com/PrimaryFeather/Starling-Framework.And click'ZIP'button to download Staring with source code.But wed need only"/starling/starlings.swc."
At the moment of writing this.「Feathers 1.0 beta」doesn't work with「Staring 1.2」,which can be downloaded directly from Staring website.That's why You shound download Staring from Grom.com.com.com.com.
If you are getting something like this:
"ArgumentError: Error #1063: Несоответствие количества аргументов в starling.events::TouchEvent/getTouches(). Ожидалось 1, получено 3. (Expected 1 argument, got 3)
at feathers.controls::Button/touchHandler()
at starling.events::EventDispatcher/invoke()
at starling.events::EventDispatcher/bubble()
at starling.events::EventDispatcher/dispatchEvent()
at starling.display::DisplayObject/dispatchEvent()
at TouchProcessor/advanceTime()
at starling.core::Starling/advanceTime()
at starling.core::Starling/nextFrame()
at starling.core::Starling/onEnterFrame()"
Be sure to reload the latest version of Starling from GitHb.com(At the moment of writing-1.3 RC(Release Cadidate)Copy theme
Now copy'asets'and'source'folders from/feat hers-1.00-beta/themes/Metal Works MobileThe me'to your project folder.And set'source'folder as sources folder for this particular project:
Select your'.fla'file
Go to'Actript 3.0 Settings'
Select'Source path'tab(if it isn't selected)
Double click on the only line in the list
Replace'/'(that is default)with'/source'
Click OK
Now remember to save all your'.as'files in'/source'folder.
Walkthrough
The follwing class shound be the root display oject that is initialized with Staring.Here's the basic struct of the clast we.Most of the code that we.Most of the code lant will goter will goto func
Create'/source/Hello Feathers.as'file with follwing content:
import starling.display.Sprite;
import feathers.themes.MetalWorksMobileTheme;
import feathers.controls.Button;
import feathers.controls.Label;
import feathers.controls.Callout;
import starling.events.イベント;
public class HelloFeathers extends Sprite
{
public function HelloFeathers()
{
this.addEventListener( イベント.ADDED_TO_STAGE, addedToStageHandler );
}
protected var theme:MetalWorksMobileTheme;
protected var button:Button;
protected function addedToStageHandler( event:イベント ):void
{
}
}
Let's start by initializing a 私.By default,the Feat hers components don't have skins.However,a the me can be instantiated in just one line of code,and it will autically provide skiss to heart theartch.atch.this.theme = new MetalWorksMobileTheme( this.stage );
ウェスpass a reference to the stage into the the me's constststtor.The theme listens for certain events to detect when a new Feaaaaaathes coponentininininininded.Whedn a new compponentinininisadded,theme the the the the theme wime will the will will inininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininatomaticaly.Most of the Feat hers examples,including this one,use the
addedToStageHandler()
.The Feat hers library cores with several themes that you may chose from.Or you cancreate your own theme.
With the me created、let's create the button and set it's label:
this.button = new Button();
this.button.label = "Click Me";
this.addChild( button );
If we want to do something when the button is tapped or clicked、we shound listen to the MetalWorks MobileThe me
event.this.button.addEventListener( イベント.TRIGGERED, button_triggeredHandler );
Our listener function shound look something like this:protected function button_triggeredHandler( event:イベント ):void
{
const label:Label = new Label();
label.text = "Hi, I'm Feathers!
Have a nice day.";
Callout.show(label, this.button);
}
This triggered listener displays a Event.TRIGGERED
compnent in a Label
component.Like with our button,these two components are atomationly skined by the me.Finally,let's position the button in the middle of the stage.First,though,let's tare note of one thing about how Feat hers controls work.Feathers uses a system of invalidation that delays redraws until just immediately before Staring renders to the screen.This keeps Feathers from from
At this moment,our button still has
Callou
and width
values of height
because it hasn't drawn't drawyet.Feaaaaaaatoststoricalalze themselves to dedesize whehen thereredraw(unexxxxxxxxxxxxxxxxxxxxxplplinininininininininininininininininininininininininininininininininininininininininininininininininststststststststststststststststininininininininininininins and other children.In this case,we want to position our button immediately,without waiting for validation.To make a Feat hers control draw*right now*,cal the
0
function:this.button.validate();
Now,we can properly center our button on the stage because it will corectly report approut dimensions based on the size of the button's skin and label:this.button.x = (this.stage.stageWidth - this.button.width) / 2;
this.button.y = (this.stage.stageHeight - this.button.height) / 2;
Full source(Staring 1.3 RC,Feathers 1.0 beta)By now you shound have:
//Hello Feat hers.fla(if in Flash Professional CS 6)
/asets/…
/source/feat hers/…
/source/Hello Feat Startp.as:
package
{
import flash.display.MovieClip;
import starling.core.*;
public class HelloFeathersStartup extends MovieClip
{
public function HelloFeathersStartup()
{
var st:Starling = new Starling(HelloFeathers, this.stage);
st.showStats = true;
st.start();
}
}
}
//source/Hello Feat.aspackage
{
import starling.display.Sprite;
import feathers.themes.MetalWorksMobileTheme;
import feathers.controls.Button;
import feathers.controls.Label;
import feathers.controls.Callout;
import starling.events.イベント;
class HelloFeathers extends Sprite
{
public function HelloFeathers()
{
this.addEventListener( イベント.ADDED_TO_STAGE, addedToStageHandler );
}
protected var theme:MetalWorksMobileTheme
protected var button:Button;
protected function addedToStageHandler( event:イベント ):void
{
this.theme = new MetalWorksMobileTheme(this.stage);
this.button = new Button();
this.button.label = "Click Me";
this.addChild(button);
this.button.addEventListener(イベント.TRIGGERED, bt);
this.button.validate();
this.button.x = (this.stage.stageWidth - this.button.width) / 2;
this.button.y = (this.stage.stageHeight - this.button.height) / 2;
}
private function bt(e:イベント):void
{
const label:Label = new Label();
label.text = "Hi, I'm Feathers!
Have a nice day.";
Callout.show(label, this.button);
}
}
}
コンサートThat shound get you started with the very baics of working with Feathers.For more information about the capabilies of the
validate()
class,read How to use the Feat the Button component.For the Button
class,read How to use the Feat Callout component.For more extensiove sample code、check out the Feat hers Examples(and their source code on Github).
For more tutoris,return to the Feat hers Dcumentation.