Actionscript 3 :: Adding Components To Stage At Runtime?
Mar 29, 2011
I am trying to ape the MS Paint application in Flash. I have a small point that I want to get cleared. I want to set the thickness of the line that I am drawing.I want to add a numeric stepper to stage dynamically. Only when I click on option to draw line the numeric stepper must appear on stage. It must be removed when I select another component.How can I add it at runtime. I got tutorials and references in which the stepper is always there on the stage. But I want it only when I want to draw the line.
When i am not placing it under a repeater tag, the components are created from XML, but if i do then the components are not getting created.
<components type="array"> <component type="mx.controls::ComboBox" title="Title One" description="Lorem Ipsum
is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
<component type="mx.controls::RadioButton" title="Title Two" width="230" description="Lorem Ipsum
is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like AldusPageMaker including versions of Lorem Ipsum.">
I need to dynamically bind properties of components created at runtime. In this particular case please assume I need to use bindProperty. I don't quite understand why the following simplistic test is failing (see code). When I click the button, the label text does not change.
I realize that there are simpler ways to go about this particular example using traditional non-dynamic binding, but I need to understand it in terms of using bindProperty.
I have a class that instantiates a movieclip from the library, eg: myBar:MovieClip = level0.AttachMovie("debugbar", "debugbar_mc", 999);
myBar is an instance variable in the class.
Now the important part - debugbar in the library is a movieclip that contains some components - buttons and textInputs. The problem comes when trying to access these components.
I would have thought that this would work: myBar.input_txt.text = "hello";
in order to set the text of "input_txt", the instance name of a TextInput component on the timeline of the movie clip (frame 1 of a 1 frame mc).
This does not work. Infact, I cannot access any specific "component" properties - they come back undefined. I cannot added event handlers for the component events either.
I can however set and retrieve MovieClip properties for the "input_txt", such as _x. However there is one added strange thing with this too - setting _visible to false doesn't seem to work (however perhaps a component by default overrides this).
I tried casting it to a component, such as: var temp:TextInput = TextInput(myBar.input_txt); trace(temp);
which gave "temp" as null. Without casting, it gives the path to correctly.
It almost seems like the components are somehow broken when trying to access them this way - or that they cannot be accessed this way?
The thing is, I was able to access all of this before, when the code to do it was placed on the timeline (frame 1, the only frame) of the debugbar itself, where the components were placed at authortime.
I need to have it in a class though, as I need to pass in certain objects that need to be accessed by the mc. I am rather baffled as to why all this doesn't work.
I created a custom textfield component that I need multiples of in a single swf. I also created a non-visual wrapper component to manage them. I am sending info from the textfields to wrapper. I was planning on using the child index to associate the info with the right component. The problem occurs when I have two instances of the textfield component and one of the wrapper on stage and I use stage.numChildren and it returns 1.
I have a dozen different custom components in my flex app. I want to use an external xml config file to load the components at run-tine. Can someone tell me whats the best way to architect this? I want to load these components and add dataProviders and event liseners to them at runtime.
I'm working on a pure ActionScript 3 AIR app, which is my first all AS3 AIR app. One thing I'm having a problem with is adding components to the app so I can see them, here is an example of the code I'm running:
public class iPhoneAIRApp_demo1 extends Sprite { protected var context:PhoneAppContext;
[Code]....
but when I run this example I don't see anything.
I guess that using Flex has made it easy for me where I can just drag components to the design view and Flex does the back ground work to add the component to the stage.
What is the process for adding visual elements to a pure AS3 project?
I'm working with the CoverFlow library by Doug McCune.
In the example included, he has created some panels inside a CoverFlowContainer. There are other examples of him populating the coverflow from an RSS feed on the page linked above but he doesn't include the source for these :(
I will eventually be retrieving data from a web service to add to the coverflow however I'm starting with this simple example:
I've defined some panels in the mxml and set creationComplete=init() so that the new panel I've created in ActionScript will be added to the CoverFlow container.
When I launch the application it displays the two predefined panels but not the one I have created in ActionScript.
im having trouble adding a progressbar components to a loader...all the images load and the progress bars too but the progress bars only change when they reach 100% and they do not disapper either..
I have a MovieClip with multiple child MovieClips. I would like to add a class to each child MovieClip. Unfortunately, I can't just create the class and mc.addChild(class) because classes aren't display objects.
I've been adding some components to a Flex 4 app (it was originally Flex 3 but has been ported). Some of these components make the app go blank when it loads. I'm not even able to see the loading progress bar. Just white.
To the root tag causes this. I also was able to make it happen when I tried setting a custom components skin from my style sheet instead of from the skinClass property.
I have a flash project that requires a swf file with over 300 textfields i.e a datasheet like in excel.i use actionscript 3 to dynamically add them at runtime.However I have a function calculate() that references them at compile time.So i think the problem is the caluclate() cannot find the textfields because they are still not added to the stage.How can i create them dynamically and after that add a function caluclate that will surely find the textfields?
Here is a code example of my work:
//add 50 textInput components for (var intr:Number=1; intr<=50; intr++) { var intTextField:TextInput=new TextInput();
I've a custom component where I do some graphics (e.g draw a line) and dynamically add a subcomponent (e.g a label) to it.
If I base the component off Group (which is recommended as per docs since its a spark component) then when I dynamically add a label the graphics part disappears.
However if I base it off Canvas this doesn't happen.
Why is that the case?
Here is the code.
MyComponent.as public class MyComponent extends Group { public var x1:int;
I created the code below which works as it should using the main timeline actions in AS3 - now, for my project I need this to work in AS3 using class files (basically I'm creating an app which uses pages as class files. This is intended to go on the 2nd page.for some reason though when I've copied it into my project and instantiated it when the page loads, even though all traces say that the squares should be there - they are not! The best I've had so far is one square in the final position![code]
how i would make a flash website that moves components according to screen size? for example the text on the introduction page of this site has the effect i am looking or: [URL]
When I attempt to create a new flash list component from my as3 file (FrontEnd.as) and add it to the stage, I get the following error: "1046: Type was not found or was not a compile-time constant: List". Below is the[code]...
I'd like users to be able to drag out a shape from the side of the stage (say a square) and then resize it on the stage. I think I've seen this Flash functionality somewhere on the web.
I've been thinking about the possibility of using Flash to create designs through ActionScript and tools that I could use at runtime. Is there any way of saving the stage elements as an image that I can use for print output later, preferably as a vector image?I realise the better option would probably be to learn how to script in java script or another language that can be used with a drawing application such as Illustrator, but I'm curious about what sort of options I have to do it through Flash.
I have an .fla file as part of Ray Media, I open the .fla to make some cosmetic changes and all of the components are in the library but nothing is on the stage. (except a pink background) File has one layer, one frame
I need to change the stage size dynamically. When I try to do this? size_mc.onRelease = function(){ trace(Stage.height); Stage.height += 100; trace(Stage.height);} It comes always the current stage size.
I am doing a project that deals with pathfinding and other AI algorithms. I am creating a city for the AI to navigate through and I wanted to no if I add all the symbols to the stage before runtime and set it up is there a way I can access all of these symbols either in an array that the stage holds. I would like to have the AI avoid them and I just figured it would save me some time if I could do it this way instead of coding the placement of 50+ items.
I have a bunch of movieclips linked with bones, with the last bone named chainEnd, and the following code on the stage.
import fl.ik.*; var tree:IKArmature=IKManager.getArmatureByName("chain Link"); var bone:IKBone = tree.getBoneByName("chainEnd"); var tailJnt:IKJoint = bone.tailJoint; var chainPos:Point=tailJnt.position; var chainMover:IKMover=new IKMover(tailJnt,chainPos);
If I set an enter frame event to change the chainPos and then use chainMover.moveTo(chainPos) the chain will wiggle about and generally act like a proper chain. (I use this so that if the cursor touches the chain it will react to it) It works perfectly. So I saved it, exported it and then used a loader to get it into a different file that I'm working with. I figured I could load it in as a movieclip titled "chain" and access the variables through chain.chainPos etc.
This works if I want to for instance trace(chain.chainPos), but if I want to do what was previously possible (react to the mouse) it just won't work. I can check for a hitTestObject for anything on the stage, and I can check for a hitTestPoint against the mouse coordinates, they trace fine, but when I want to actually have the chain move the chainPos and chainMover.moveTo don't seem to do anything. (Interestingly enough chainPos still updates it's coordinates, so if I do chain.chainPos.x += (put number here) and trace that, it will actually change) Anyway, I was wondering if anyone knew why this wasn't working, or could help me get this functional. It's a massive pain to have the bones/movieclips on the stage rather than loaded in as a movieclip, so if possible I'd like to avoid that.
I am working on a text adventure game which will have at least a few components (a text area for narrative and text input for user input) on the stage at all times. Therefore, I have created those components statically through Flash's WYSIWYG design environment. I gave them instance names "myTA" and "myTI" respectively. I was able to get my main class (the document class for the stage) to interact with them (dynamically adding text one character at a time like a typewriter at runtime), but other classes in the same package don't seem able to recognize the stage components. Below is the relevant [code]...
I'm trying to build a flex project, linking it to some RLSs. When setting up the project in Flex Builder, the corresponding "build configuration" (that I got by adding -dump-config to the compiler options) generates (among other things) a tag like this :