ActionScript 3.0 :: Converting GetChildByName() Acquired Object To Other Class?
Feb 17, 2009
I've been wondering if it is possible to convert an object acquiredby a getChildByName() function to another class?Let's say i have a library item designated as MovieClip and it is a part of some "sprite sheet". Now, when i need some sprites for my program i create a new sprite sheet instance and then i take sprites from it using the getChildByName():
Code:
sourceSheet = new UISpriteSheet();
someObject = sourceSheet.getChildByName("someObject");
I am a VERY basic user with Flash and have been asked to make an auto-scrolling news ticker for our website. The ticker needs to be able to pick up text from an external text file (so that we only need to alter the text file rather than the .fla file). AND, if possible, it needs to update automatically each day... I'll explain in more detail as I imagine this is very hazy so far. The news ticker will display up-coming events for the following two weeks on our website. So on, say, Monday the 1st it will show something like:
I'm using TweenLite for my Tweens. The constructor takes the form weenLite(targetDisplayObject, duration, object). The third parameter specifies the parameters of the tween, in the form {x:100,y:100,ease:Back.easeIn} etc. What I want to do is this:
Code: var str:String = "{x:100,y:100,rotation:Math.random()*360}"; var obj:Object = convertToObject(str);
This will probably seem a moronic question, but I've only been using Actionscript for about a week... Either way, I've written a very long and complicated (8500 lines w/ autoformat) code for a game I've decided to program. The game is functional, the AI can respond to outside inputs etc, and I know reasonably well how to use SharedObjects.
What I'd now like to do is make a menu system surrounding my game that can pass variables in and out of this existing program. The program is currently in the shapely form of a Document Class, meaning the code runs on load. I'd prefer if there was a way to simple make the code run upon being called. How would I best do this? The only inputs presently used are keyboard inputs...
I am trying to create a small game that plays videos when you click a button. The following code works effectively;however, it is placed on an action frame and I would like to convert it into a class so that later on additional functionality may be added.I am more of an animator then a programmer but am trying to learn so that I can make games.[code]
I've faced a problem converting an Object into String in flex . my object is mydropdown selecteditem and I want to convert it to string and show it on a label tag . I've tried ".toString()" and "as String" and "String()" but none of them worked
i have a collection looking like this :arr.getItemAt(0).closet.clothes[0].color. the arr is an ArrayCollection data type..the clothes is an Array data type..when i try to bind this to an mxml component , i get a warning :"Data binding will not be able to detect changes when using square bracket([]) operator. For Array, please use ArrayCollection.getItemAt() instead."this is not possible as the Array class has no method getItemAt().
I'm trying to play a sound using a technique found here (play the sound by sampling raw sound data gathered from the original with extract()), with the difference that the mp3 sound is embedded in the swf, not loaded externally. This is my code:
var soundBytes:ByteArray = new ByteArray(); var mp3sound:Sound = Sound(new Sound1_design()); // this is the embedded sound mp3sound.extract(soundBytes, int.MAX_VALUE);
[Code]....
This works, in a way, except that the resulting sound is distorted (it has a kind of a metallic ring).
I have an ArrayCollection and each element is an instance of the TreeNode class (a custom class made by me) that has a "children" property which is an ArrayCollection of more TreeNode elements. That way, I have a tree of elements in an ArrayCollection structure:
tree = new ArrayCollection([ [new TreeNode(param1, param2, new ArrayCollection([ [new TreeNode(param1, param2, null)],
[Code]....
But my problem is: I need to have the same "tree" structure (it doens't need to be the same variable) filled with instances of another class. How can I achieve that?
Well I finaly found a script that's pretty easy but interesting to use.Then I thought, why not help the community out and try to convert it into a class which would be very dynamic and easy editable.Well I figured out how to draw a dynamic mask, but after that I can't seem to figure out how to implement the mouseOver/imgPanning into the same piece of code.[code]The commented section is the code that makes the img pan, but I cant seem to figure out how to implement this so people can still use the drawRectangle function.
I'm having some troubles with the use of interface and inheritance in AS3. I've done lots of OOP in the past and what I'm trying to do seems obvious to me, but doesn't work in AS3. The question is : Is it possible to override a function that return an Object of class A, and make it return an Object of Class B which extends A ? It seems not to be possible, since I'm getting a signature error in Flash, when compiling. For example, the following set of class do not compile (the code in function definition doesn't matter):
I am developing a mobile project in Flash builder using flex 4.5. I am very new to flex, with some background in Obj-C.urrent Setup:I am passing the text property of a text input component to a second view via navigator.pushview{view.Someview, data}public function doSomething():void{navigator.pushView(Session_View, timeInput.text);This successfully passes the text I put into the textinput to the Session_View instance and I can display that text in a label in the mxml; however, I would like to take the text passed and convert it to an integer to use in my logic.Within Action Script I have tried parseInt() function with no luck.I have also tried to assign data to a variable in actionscript with no luck.
I have a class CoverPoint extends Pointwith some extra function.except for that ther is no difference. I would like to use the functions of Point with a return value of Point, to calculate those CoverPoints.Can i turn the return value into CoverPoint (since all the vars are the same, there shouldn't be a problem with that, right?), so that it can be stored in my var cP:CoverPoint;
I am currently pulling data from an s3 storage account. S3 has a flat file structure but gives the impression that the files are stored in directories. how do I convert this String[]
I am using grails to render the data as JSON for a flex application using an Advanced Datagrid and need a tree like structure, as if you were browsing files on your desktop.
I need to instantiate them as instances of a custom class I have created. This is giving me an error, and I know I'm probably missing some simple concept somewhere, doing something wrong, but I don't know what it is.Here is my code:
In the main timeline, I have (simplified): var puzzleAL:GeoGroup = new GeoGroup ("AL", "Alabama", 1, false); puzzleAL.addEventListener(TouchEvent.TOUCH_BEGIN, geoTouchBeginHandler);
I'm trying to declare a movieclip variable in a class by finding the instance name of the movieclip.
On my stage I have a 'Container' (linkage class name) MC, inside that is a 'PlayerInfo' (linkage class name) MC inside that is a 'healthBar_mc' (instance name) MC. healthBar_mc is what I'm trying to access.
the class where I'm trying to run this function is linked to a MC inside 'Container'
I'm trying to use XML to load in 4 images to a movieclip within a movieclip that is already created on the stage. I'm trying to do this in a loop since there are 4 movie clips I'm trying to access. I can get it working without the loop, but it's figuring out the syntax that's causing the problem. Currently I have the following code:
function ParsePics(picsInput:XML):void { var picsList:XMLList = picsInput.pic.image; for (var i:int = 0; i < picsList.length(); i++) {[code]..............
I have many MovieClips and each has a name like "mcDummyClosed" and then and instance name "slideDummyClosed". Another MovieClip has a link to e.g. slideDummyClosed which I then call DummyClosed. I add a MouseEvent.CLICK event to DummyClosed.
Now without adding slideDummyClosed to the stage nor any other MovieClip can I with a string containing it's name get that instance? I've tried using getChildByName() but that only seems to work if I've already added the MC to be found and added before. My code looks something like this:
I seem to be having a bit of a problem here. I'm generating a load of class instances using the following code:
maxpersons=25; for (var i:Number=1;i<=maxpersons;i++) { var person:Person = new Person;
[Code].....
OK. I then need to run through each of them and check for a collision with an object from the main stage (called redDot), which I pass to a method (called doDamage) within the class. I'm using the following code:
for (i=1;i<=maxpersons;i++) { if (game.getChildByName("person"+i).hitTestObject(red Dot)) { game.getChildByName("person"+i).doDamage(redDot); } }
I keep getting an error saying "1061: Call to a possibly undefined method doDamage through a reference with static type flash.displayisplayObject."!
It just won't work. I've tried altering the code to:
game["person"+i].doDamage(redDot);
but I get an unexpected trace output saying "TypeError: Error #1010: A term is undefined and has no properties."
I have a several functions that I can compact into 1 function via a for loop if only I can find a way to call the variable by name.
For example:This is what I want to accomplish: (However I do not have the slightest clue as to how to go about doing the below...)
ActionScript Code: var test1:String = "testing 1"; var test2:String = "testing 2";
[code].....
I am able to do something similar to the above when using objects using methods such as: (I know not efficient, but its just an example to show what I am trying to accomplish.)
ActionScript Code: var test1:String = "testing 1"; var test2:String = "testing 2";
nav_mc.getChildByName("go" + i + "_mc").alpha = 0; // this works fine
but then if I add this:
nav_mc.getChildByName("go" + i + "_mc").gotoAndStop(2); // Doesn't work nav_mc.go1_mc.gotoAndStop(2); // Works
nav_mv is a MC on stage, it's child is another mc whit 2 frames in use.why the gotoAndStop doesn't work with the getChildByName?this is the error I'm getting: 1061: Call to a possibly undefined method gotoAndStop through a reference with static type flash.display: DisplayObject.
I'm trying to use the getChildByName function and for some reason it's not working. Here's the line that is causing the error of "TypeError: Error #1006: getChildByName is not a function."
PHP Code:
var contactBox:MovieClip = anyBox.getChildByName("earthBox" + i);
It is in a for loop and is definitely calling to a movieclip of the correct name in the MC array anyBox. I've searched the internet and haven't found anything (On the first page of google...)
I'm working on a function that replaces an existing movie clip with a symbol from the library and then designates an "updater" function for the new instance. I have the first part working as intended, but I'm not sure how to approach creating the "updater" function.I've considered using event listeners, but I'm not sure if that is my best option.The following is a excerpt from my code. This code is on the timeline of a movie clip. The movie clip is on the main timeline with an instance name of slideUpPanel_mc.
ActionScript Code: var window_mc:MovieClip = window_mc; //window_mc as it exists on the timeline var windowUpdateFunc:Function; //reference to updater function in window_mc