004 工作與CLIK按鈕欄的

Post date: 2012/11/22 上午 10:10:14

QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ.

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.

There are no working examples of using the ButtonBar in Unity; however, you can use the ButtonBar_MainDemo in Unity by simply copying these files into your StreamingAssets folder:

(found here: ...\[Scaleform SDK]\Resources\AS3\CLIK\demos)

ButtonBar_MainDemo.fla

ButtonBar_MainDemo.swf

Component_Library.fla

Component_Library.swf

\com\scaleform\demos\ButtonBar_MainDemo.as (being sure to save this in the same directory structure inside your StreamingAssets folder)

Next, on frame 1 of the root timline of ButtonBar_MainDemo.fla, open the Actions panel (F9) and enter:

import flash.external.ExternalInterface;
ExternalInterface.call("RegisterMovie", this);

... and publish the movie.

Then, in your movie C# file:

protected Value movie = null;
protected Value buttonBar = null;
protected Value dataProvider = null;
//Called from ActionScript above via ExternalInterface
public void RegisterMovie(Value movieRef) {
    //Cache a reference to the Scaleform Movie, then run the init() function
    movie = movieRef;
    init();
}
private void init() {
    //Cache a reference to the ButtonBar1 instance
    //ButtonBar1 lives inside the TextInputDemo movieClip on the root timeline
    buttonBar = movie.GetMember("TextInputDemo").GetMember("ButtonBar1");
    //Next, we'll cache a reference to the ButtonBar's dataProvider
    //The dataProvider is an array of objects; each object contains a button label
    //See the _content array in the ButtonBar_MainDemo.as file
    dataProvider = buttonBar.GetMember("dataProvider");
    //Displays the currently selectedIndex of the ButtonBar
    //Each button in the ButtonBar has an index value, staring with 0 for the first button
    Debug.Log("selectedIndex: " + buttonBar.GetMember("selectedIndex"));
    //Displays the label of index/button 0 as found in the dataProvider
    Debug.Log("label of button 0: " + dataProvider.GetElement(0).GetMember("label"));
    //To set the selectedIndex of a ButtonBar use:
    buttonBar.SetMember("selectedIndex", 1);
    //To set/change an element of the dataProvider use:
    dataProvider.GetElement(0).SetMember("label", "Testing");
    Value retVal = new Value();
    dataProvider.Invoke("invalidate", new Value[0], 0, ref retVal);
}

To get the selectedIndex whenever the user presses a button in the Button bar, you first need to add the following bit of code to ButtonBar_MainDemo.as, inside the handleIndexChange() function:

ExternalInterface.call("onIndexChange");

... and publish the movie.

Then, add the onIndexChange() function to your C#:

public void onIndexChange() {
    Debug.Log("selectedIndex: " + buttonBar.GetMember("selectedIndex"));
}

Alternatively...you can initialize a ButtonBar’s dataProvider from C#, without any ActionScript like so:

dataProvider.SetElement(0, new Value("Testing1", MovieID));
dataProvider.SetElement(1, new Value("Testing2", MovieID));
dataProvider.SetElement(2, new Value("Testing3", MovieID));
 
Value retVal = new Value();
dataProvider.Invoke("invalidate", new Value[0], 0, ref retVal);
avatar
avatar
avatar
avatar

How do you add items to buttonbar in Unity or from Unity to the ButtonBar?

Do you have a small demo for this?

Do you have a simplified example in Unity3D + ScaleForm + ActionScript + clik for this.

Question is:

How do I add a data-provider to ButtonBar?

I added it, but it causes a render error to occur.

Hi-

Do you mean a render error in ActionScript or a C++ crash?

-Ankur

Hi,

I meant,

How do you use clik.button-bar?

Example:

I copied and pasted the “Import:$font” from ButtonBar_MainDemo.fla to a new FLA file.

It gives error on run:

2012-11-03 02:08:38.660 FxMediaPlayer[5818:707] NSDocumentController Info.plist warning: The values of CFBundleTypeRole entries must be ‘Editor’, ‘Viewer’, ‘None’, or ‘Shell’.

Then,

I browse to ActionScript 2.0 demos: the directory is marked “DemoTBD” which is empty.

I browse to ActionScript 3.0 demos:

ButtonBar_MainDemo.as -->

...

public class ButtonBar_MainDemo extends UIComponent { <-- what if you don’t use Extends UIComponent like a normal FLA script? What should you do next?

...

var _content:Array = [ { label:"Home" },

{ label:"Forums" },

{ label:"Scaleform" },

{ label:"CLIK" } ];

public var ButtonBar1:ButtonBar; <-- how is this linked to the FLA object that has no variable?

override protected function configUI():void {

} <-- what if you don’t use this style?

ButtonBar1.dataProvider = new DataProvider(_content); <-- error: _content not found if you copy&paste this to blank FLA file.

Do you have any Unity3D examples where data is sent from C# Unity to the ScaleForm Buttonbar,

then SelectedIndex data to Unity3d?

  • am964
  • Posted: 2012-10-29 12:15 PM