all groups > flash actionscript > september 2005 >
You're in the

flash actionscript

group:

Component buttons in movieclips


Component buttons in movieclips Ed NO[at]SPAM Home
9/10/2005 10:29:53 PM
flash actionscript:
:confused;I have drug a button component (instance name: myButton_btn) onto a
movie clip in the library. I have set the library movieclip linkage for
exporting. I now use the this.attachMovieClip(xx, xx, xx) on a frame in the
root timeline to place a copy of the library movieclip on the stage with the
instance name of myClip_mc. I now attempt to label the button using the AS
below in a root time line frame.

myClip_mc.myButton_btn.label = "test";

No label appears when I test this movie, but a blank button does appear. Does
anyone have an ideal what I am doing wrong?
Re: Component buttons in movieclips Alex Fex
9/10/2005 11:53:41 PM
I'm going to have to assume you have made a text field inside of the button
symbol or movie clip with an instance name of label. If this is the case, then
you need to add .text.

_root.mymovieclip.mybutton.label.text = "string";


Re: Component buttons in movieclips Ed NO[at]SPAM Home
9/11/2005 12:18:59 AM
Label is a property ovf the button component and I shouldn't need to use a text field. If I place the AS

myButton_btn.label="test";

In a frame of the library movieclip.t works fine.

Re: Component buttons in movieclips LuigiL
9/12/2005 8:32:05 AM
If you want to create buttons (or other components) dynamically, you can use
the following approach. Make sure a copy of every component you want to use is
in the library.



// import the component classes in case you want to use other components too
// else use import mx.controls.Button;
import mx.controls.*;
// attach mc 'box_mc' from the library
var container:MovieClip=this.attachMovie("box_mc","box_mc",1);
// create a button in the attached movie
var myBtn_btn:Button=container.createClassObject(Button,"button1_btn",1);
// position the button
myBtn_btn.move(20,20);
myBtn_btn.label="Test";
myBtn_btn.onRelease=function():Void{
trace("This works just fine.");
};
Re: Component buttons in movieclips Jpmon1
9/14/2005 12:00:00 AM
LuigiL,

I don't quite understand what you mean by:

"Make sure a copy of every component you want to use is in the library."

I tried to implement the code in a blank flash document, but no button.
I am trying to dynamically create buttons.

Thank you,

Jon
Re: Component buttons in movieclips LuigiL
9/14/2005 12:00:00 AM
If you test the code in a blank flash document do the following:
drag a button component to the stage from the components pane. Now delete the
button. You now have a copy of the button component in the library. Test the
movie.
Re: Component buttons in movieclips Jpmon1
9/14/2005 12:00:00 AM
Ok, nevermind, I found out my problem.
I did not link my movie clip properly.

Re: Component buttons in movieclips Jpmon1
9/14/2005 12:00:00 AM
Couple of more questions:

Can you add more than one button to the same movie clip/container?
I have an array of variables, and I would like to create on button per
variable, how would I go about doing that?

Thank you
Re: Component buttons in movieclips Jpmon1
9/14/2005 12:00:00 AM
LuigiL,

I dont know if you go my last message, because I replied to my own post. I
saw your speed resoponse, so I figured, you were notified every time some one
replys to your messages. Sorry to bug you, but I had a couple more questions
that I posted.

Thank you.
Re: Component buttons in movieclips LuigiL
9/15/2005 9:00:58 AM
You can create more buttons and you can create complete forms using all the
components you need. An example to create more buttons (I use an empty
movieclip this time):



// import the component classes in case you want to use other components too
// else use import mx.controls.Button;
import mx.controls.*;
// create an empty movieclip to hold the buttons
var container:MovieClip=this.createEmptyMovieClip("box_mc",1);

var buttonText:Array=["Test 1","Test 2","Test 3"];
var rollOverText:Array=["This is button 1","This is button 2","This is button
3"];

// create buttons in a movieclip
function createButtons(target_mc:MovieClip,numberOfButtons:Number):Void{
for(i=0;i<numberOfButtons;i++){
var
myBtn_btn:Button=container.createClassObject(Button,"button"+i+"_btn",i+1);
// position the button
myBtn_btn.move(20,20+(30*i));
setButtonText(myBtn_btn,i);
setOnRelease(myBtn_btn,i);
}
}

function setButtonText(target:Button,i:Number):Void{
target.label=buttonText[i];
}

function setOnRelease(target:Button,i:Number):Void{
target.onRelease=function():Void{
trace(rollOverText[i]);
};
}
// and create the buttons in our empty movieclip
createButtons(container,3);
Re: Component buttons in movieclips Jpmon1
9/15/2005 11:54:01 AM
AddThis Social Bookmark Button