Previously in my code, I had a Variable, Chip. Chip moved around the screen and everything was fine.
var chip:Shape= new Shape();
chip.graphics.lineStyle(0,0);
chip.graphics.beginFill(0x3333FF,0.8);
chip.graphics.drawCircle(0,0,10);
chip.graphics.endFill();
was the code to make chip. Now I've make a movieClip and I would like to use the movie clip instead, so I know I'd start with something like
var chip:movieClip;
but I'm lost after that. How would I be able to use him in place of making the shape?
So I'd guess that you are using Flash IDE and have created a movieclip for your Chip that is now in your library and you don't know how to add it to the stage :)
Right-click on your movieclip in the library and select "Properties". In the advanced section select the "Export for actionscript" checkbox and give your movieclip a linkage name in the "Class" Input field, for example "Chip". Leave the "Base name" as MovieClip.
Now your movieclip is accessible via actionscript and you could add it to your stage:
var chip:ChipMC = new ChipMC();
addChild(chip);
trace(chip.x, chip.y);
Related
I've tried this as many ways as I can figure out. I went to convert to symbol > movie clip, but that doesn't allow me to go into the properties to link anything to where it will have a symbol in the linkage column in my library.
I need to take my png's, turn them into movie clips, and then link them. Does anyone know how to do this? Or if I am doing it right, why it's not working?
Use Sprite class, as PNG is not an animation sequence, then use graphics.BeginBitmapFill() programmatically. Or, create a new Sprite or MovieClip descendant class in library, there make a bitmap-filled rectangle and use your PNG as fill pattern.
In Adobe Animator/Flash. Insert > New Symbol (Check Export for Actionscript and change the class name to whatever you want.. ie: MyImage) Double click MyImage in the library and drag your image into the movieclip on the stage. Now in your actionscript you can create it dynamically. If you already have a movieclip in the library with your image in it right click on it and select properties, then check export for actionscript.
var img = new MyImage();
I'm new to Adobe Flash. I'd like to create a button or component in Flash Professional using MovieClip and add label to it, and build my own button with special functions.
And i'd like use ActionScript to edit code. I faced a problem: i can not edit all code of my component (that cotains several ui-elements) in one AS3 class. I create empty document, add rectangle to it, then convert it to symbol. Next, i go to Advanced ActionScript 3.0 Settings of IDE, add path to folder where i put my Class.
Then add MyClass to Document class in that window.
But when i add new elements to the document, it doesn't appear in MyClass.as
Is it possible to edit complex component in Flash IDE in one ActionScript class ?
Sorry for a long explanation and for my poor english.
I create empty document, add rectangle to it, then convert it to
symbol.
Make sure symbol is type: MovieClip. Give it a name you prefer (no space is good idea). Further down (see Advanced section?) there is section called Linkage click "Export for ActionScript" and remember the name shown in Class box (you can edit it) and just click OK. No need for folder paths etc.
Lets assume the name used for Class is : myComponent
Now you can use it in your code. To make a document class open the Properties panel (ctrl+F3) and just type a name example Main (no extensions) and press enter and then save FLA and secondly also save the class code (it will ask for a file name so use as Main.as).
Now If you click that pencil icon in properties you will be editing class code (Main.as) for the FLA document and it knows your component if you reference it by code:
public var test_comp : myComponent = new myComponent (); here test_comp is just a quick reference name. Use your own preferred reference name.
You can edit the MovieClip of myComponent by right-clicking and choosing "edit" (not "edit Class"). Now you can add/draw different things and even convert them to Graphic or MovieClip and give them instance names. A MovieClip object is like a mini-stage so it has its own unique timeline and you can work exactly like if this was the main stage (but without actually affecting main stage).
If you add something to Component MC such as drawing a circle (as some button?) and convert that circle to MC or Graphic type with instance name circle1, in the code you access that as:
test_comp.circle1.alpha = 0.5; since test_comp is your code's reference name for that myComponent MC in the Library.
After testing the above example... now begin your own component.
Remember... If an object is inside the MC access it via it's instance name and if you need to addChild it from the Library instead then use its AS3 linkage name.
I have created a Flex project in Flash Builder 4.5.
Next I added fl.controls libraries (and then mx.controls libraries) in the project.
I am adding a screenshot so you can see the setup and the code.
However when I run/debug it, nothing appears in there. Totally white.
I've worked with fl.controls before, I used Flash CS5 to compile the ActionScript project and they worked correctly.
Is there any particular reason why it does not work in Flash Builder?
UPDATE: When I add graphics to the text input, i.e.
ti.graphics.beginFill(0xFF0000);
ti.graphics.drawRect(0, 0, 100, 30);
ti.graphics.endFill();
I do see a red rectangle shape. But still no editable text input box. I tried setting ti.editable = true but no use.
Try this:
Create a new FLA in Flash Professional. Add the TextInput component to your library. Notice that not only does the TextInput class get added to the library, but also a folder of "Component Assets" - skins and such. Flash Professional components are not just code - they are code and graphics.
If you want to use fl.controls.TextInput in Flash Builder, you can publish that FLA you just created with the "export swc" option checked. Include that swc in your Flash Builder project, and you'll be able to instantiate the TextInput in your code. If you want to add other Flash components, add them to the library in the FLA and republish the swc.
I would prefer using Flex itself, it will speed up your development. It's simple and does a lot of work for you.
If you do not want to do this you should give your text some properties like width, height, textFormat or use a css document for the text format. You could also give your text a border ( it should be a property of the TextInput ).
Do not forget to set the text format, otherwise the TextField doesn't know which font to use.
Sample for TextInput ( Bottom of Page )
http://help.adobe.com/de_DE/FlashPlatform/reference/actionscript/3/fl/controls/TextInput.html
Sample for Flex
http://help.adobe.com/de_DE/FlashPlatform/reference/actionscript/3/spark/components/RichEditableText.html
You can try this code:
private var ti:TextField = new TextField();
public function FormText(){
//adds ti possibly underneath 'this': stage.addChild(ti);
//adds ti on top of 'this':
stage.addChildAt(ti,getChildIndex(this));
// makes the TextField editable:
ti.type = TextFieldType.INPUT;
}
This should not only make sure that the TextField exists when the class is instantiated, but also puts the form in front of the class.
But this also assumes that the class has been added to the stage; so it may be better to add it like this:
private var ti:TextField = new TextField();
public function FormText(){
addEventListener(Event.ADDED_TO_STAGE, addedHnd);
}
private function addedHnd(e:Event)
{
removeEventListener(Event.ADDED_TO_STAGE, addedHnd);
//adds ti possibly underneath 'this': stage.addChild(ti);
//adds ti on top of 'this':
stage.addChildAt(ti,getChildIndex(this));
// makes the TextField editable:
ti.type = TextFieldType.INPUT;
}
Please review the TextField docs, too.
Why do you add your control to the stage? You should just add it to your form. i.e. this.addChild(ti)
I have 27 MovieClips in my Library which are all images. At the moment they are positioned on the stage as instances of their parent and then made to function in the first frame of my actions layer. I want to recreate this layout solely in code so there is nothing on the stage. How do I do this?
Thanks in advance.
Sam
Right click on a movieclip in the library, then go to Properties.
Tick "Export for ActionScript", then check the name where it says "Class". Hit OK.
Let's say this name was "Symbol1".
Then type this script:
var symbol1:MovieClip = new Symbol1();
addChild(symbol1);
var symbol1 means you created a variable, MovieClip is the type. This MovieClip variable is a "new " Symbol1 (this was the name in the library, Properties, Class.
Then add this to the stage:
addChild(symbol1)
If you want to position it on the stage, set the coordinates of the variable:
symbol1.x = 10;
symbol1.y = 10;
puts it to (10, 10).
Depending on how many objects you have you can type this code for each one of them (don't forget to Export them for actionscript in Library->Properties).
If you have tons of movieclips and you don't want to type evertyhing, but would rather write some dynamic code, give us a hint on your library structure and how you named your objects.
Hope this helps.
In Flash CS5 I have a button with an instance name "btn", which is made up of movie clips with instance names "mv1" and "mv2".
The question is: can I use gotoAndStop or something similar on the movie clips inside the button from the stage in which the button is instantiated. In pseudocode:
btn.mv1.gotoAndStop(3);
btn.mv2.gotoAndStop(7);
This is likely to be a very basic question, but the one I could not find any information on in the last half an hour.
Probably yes, if btn happens to be a MovieClip. For (almost?) any other display class (DisplayObject, DisplayObjectContainer, Sprite etc) this will fail in compilation.
If your compiler refuses to run your code, try this:
var mv1:MovieClip = btn.getChildByName("mv1") as MovieClip;
mv1.gotoAndStop(3);
Yes you can.
btn.mv1.gotoAndStop(3); will work perfectly fine.