ActionScript 3.0 :: Accessing Object From Other Object
Jul 20, 2011
I'm just starting with OOP in AS3 so apologies if this question is too simple...The goal of this script is to have a button change it's own features (colour and transparency) and change the alpha value of a loaded picture.There are 27 buttons for 27 (stacked) pictures.In the fla is the following code:[code]When I try to access the picture (= portrait class and the test_portrait var in the fla) it can't be found. The object and the loader have for example this path when I debug: Movie Clip: Frame=0 Target="_level0.p_4.l_4. But when I do trace(getChildByName("p_"+tmp_name)); in the P_button class it returns null. Doing the same trace from the fla returns: [object Portrait] Why can't I access it from the P_button class?
What I should do is parse an xml and from its node name create object property and then create an object array based on those property. Am I able to make myself clear.
I have 2 classes, Display holds the currently selected Component:
public class Display { public static var selectedComponent:Component; }
Component has an ID string and the selectedComponent variable is set on click:
public class Component extends MovieClip { public var id:String; addEventListener(MouseEvent.CLICK, function() {
[Code]...
Removing the selectedComponent variable type so it reads public static var selectedComponent; removes the conversion error and seems to change the ID variable but it appears to only be a copy of the object.
I have problem with accessing object created by function imported from another package. I have 2 packages DragDrop and UserInterface. In UserInterface I create methods for buttons and later add them in DragDrop . I make it in two different ways: One(this one works):
Ok, so I made a custom class, but I did not want to add all the text to it through code (much easier to type it in flash on the frame). I name the instance aScoreBoard.
As my code runs, I need to call some of the functions that are part of the ScoreBoard class. As the code gets to this point, I try this line:
aScoreBoard.UpdateScores(passArray);
which will update the scores on the scoreboard. When that line in AS3 tries to execute, I get this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference. at Main/Main:ayEnd()[C:projectsDev_LearningLongJumpsrcMain.as:616] at Main/Main::ButtonAfterJump()[C:projectsDev_LearningLongJumpsrcMain.as:606]
Is there a way to do things this way? or will I have to go and do all the extra text entering in the code?
I am trying to access an object I created from an another object.I have the document class main.as and two other classes player.as and console.ascircle.as is draws a circle on the stage and logger.as is a simple class that I will use to trace stuff and record data.In main.as I created both two objects and I want to be able to access the console class methods from player class (and all the future classes that I will write)Main.as:
So I have this Photo class than handles loading a pic, and dispatches an event when the loading is done with:[code]which is simple and works, but now I'd like to make something more advanced. I'd like to dispatch the load ratio.So far I have extended the Event class, with my own EventRatio class, and I can put properties on that class. Which is cool, but I need something more dynamic than just sending a fixed value.So, what is the best way to connect the Loader object of the Photo object, with the EventRatio object?
I'm doing some work with JSON in as3 using as3corelib (very useful) and was wondering if it is possible to get an object if all you have is one of its properties, also an object. Here's an example of some JSON:
"parentObject": { "propertyObject": { etc. } } so what i'm asking is, if I have propertyObject, can I access parentObject somehow?
I have a project that i'm working on, and in the project it's important that i have an object that i can create with actionscript that already has two arrays inside of it. To do this, i made the movieclip, i checked export for actionscript in the library, and in the custom class that corresponds to that object i made the arrays with the following code:
package { import flash.display.*; public class cont extends MovieClip {
I have have a problem loading and accessing data from a value object in my new project.. I load an xml file via a service, which contains title and locations of asset files, I need to be able to access the location of an asset file by specifying the title and retrieiving it from a value object.. I'm using the Robotlegs framework, here's an example of the xml:-
ActionScript Code: //Main.as -- document class public var content:Content; something something ;
[code]....
What I need to do in Carousel.as is that, get the images in the MC to carousel (d'uuh).So, how do I get those objects from the Carousel.as class? I have declared the names of things in it as public vars but no luck so far.
Hierarchy of content:
content --on some frames-->carouselcontent(named in IDE - of Carousel type)-->image1, image2, image3(all named in IDE)
In actionscript an object's property can be accesses in this way: object["propertyname"] Is something like this possible in c#, without using reflection?
I have a HTML page that contains a flash file and some a JavaScript function that returns the object of the flash file.So far I can call the JavaScript function from C# and have it return an Object, but I want to cast it as AxShockwaveFlash and access the COM Object directly from C#.I have seen this done with Windows Media Player imbedded in the a HTML page, but it doesn't seem to work with flash.[code]When I try to cast the Object to AxShockwaveFlash it fails, but I have seen it work casting the object to WindowsMediaPlayer.I tried to find if AxShockwaveFlash supports QueryInterface calls, as per the error message but Google returned nothing of value.
I have an engine I created a while back that loads objects into a container based on XML data. A really quick example of the XML would be like this: <level> <object cname="enemies.Robot"> <pos x="200" y="400" layer="mobiles" /> </object><object cname="Player"> <pos x="12" y="89" layer="mobiles" /> </object></level>
I have a class Environment that has a method loadLevel(data:XML) which I parse the XML through, then the function runs through the XML finding all object nodes and uses getDefinitionByName to determine which Object I want to create based on object.@cname. From here, I have to manually define each property based on the XML like so: obj.x = xml.pos.@x; obj.y = xml.pos.@y; etc.
I was wondering if there's an inbuilt method for setting a property based on a String. By this I mean something like so: var mc:MovieClip = new MovieClip(); mc.someInbuiltFunctionThatSetsAProperty("alpha", 0.5);
This way I could change my XML to be more like so: <object cname="Player"> <props> <x>200</x> <y>221</y> <alpha>7834</alpha> <health>Something</health> <power>3</power> </props></object>
And iterate through all the children of props to set all of my properties on the fly. I know if I create an Object and set properties within it like so: var obj:Object = { var1: "hello", var2: "there", name: "marty" };
That you can then iterate through names/values using the for(String in Object) loop like this: var i:String; for(i in obj){ trace(i + ": " + obj[i]); } /** * Output: * var1: hello * var2: there * name: marty */
Surely there's a way, as here's an example of identifying a property using a String: var ar:Array = [new MovieClip(), new MovieClip()]; ar.sortOn("alpha", Array.ASCENDING); So just to make my question more to-the-point: I want to be able to get and set properties that I can identify using a String.
I'm using FlashDevelop as IDE and I'm trying to connect to AMF3 service (amfphp) and get user details.I can connect to AMF service with this code in AMFinit() function...
private function AMFinit():void{ AMFService.objectEncoding = ObjectEncoding.AMF3; AMFService.connect(AMFServiceURL); AMFService.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
[code]....
But to use outside the AMF_MyUserInfo() function I want to copy that "res" object to another object. I tried with specifing an object in Class and set res to this object in AMF_MyuserInfo() function with "this.myobject = res" but it didn't work.
I also tried "this.myobject.username = res.username" but it didn't work also. how can I use this res object globally or in AMFinit() function?
So I am writing a program which uses Dictionary to store objects. For example
var dictionary:Dictionary=new Dictionary(); var myObject = new myObject(var1, var2, var3); dicionary["key"]=myObject;
where var1, var2, and var3 are simply means of assigning values to variables in myObject.can I access values or functions that are found in myObject? In myObject class I have some getters and setters. Can I use a getter to get the value of var1 for example.
I am new to action script working with flash cs4 with action script 3.0. How do i access a UI object(stored in .fla) in action script. I have already linked these two files. It is working fine. I have a button as UI object, that was converted as symbol and instance name has already given. I cannot access the button using the instance name in actionscript. If i tried so there is no intellisense. How do i access it in script. I am using oops style of coding.
How do you access a child that has been added to an object?For example if I have a movieClip on the stage and I add a child to it, how do I then access that child?
Code: var newClip:MovieClip = new MovieClip(); newClip.addEventListener(Event.ADDED, checkClip);
I need to store a users username that has successfully logged onto our system.
The user will be accessing a directory behind the corporate firewall.
I've talked to IT about it... they have said.
Quote:
I can put an integrated security virtual directory in place.
In turn, you would need to figure out how to get the �current logged on user� details from the environment variables that are in the request object (that comes from the user�s browser to the webserver).
Is there a way out there to essentially loop through a generic object to find out what parameters/properties are being used and/or what there names are?
ActionScript Code: var obj:Object = new Object(); obj.foo = "hello"; obj.bar = "world"; //... and on for however many params you need [Code] .....
I might be trying to do something that is essentially not possible, but I'm just thinking it would be very nice sometimes to access different parts of an object without having to directly know what the param name is...
How would I go about accessing the object I am moving with a tween through TweenEvent? or is this even possible? I think e.currentTarget will give me the tween object instead of the movieclip it is controlling, but I'm not sure.
Example: ActionScript Code: var tweens:Array = new Array();
I have created a sharedobject on a local hard drive that stores multiple objects in it. I need to know how to access one particular object in that sharedobject.
I have a custom property called Player (like a basketball player) that has properties for points per game (ppg), rebounds per game (rpg), etc.I'm designing a piece where users can get averages and compare players across many different categories.
I have a String variable "stat" that tracks which property they want to compare. I can use "stat" in a sorton function, but need to use it to access the object property. So when the user chooses "ppg" or "rpg" i can access Player.ppg and Player.rpg by using the stat variable. Player.stat doesn't work.
Document Class have a stageRef:MovieClip object (same size as the swf) that all the other displayobjects are added.And I have 2 more classes: createLevel and Player. Player class generates a box object and adds it to the stageRef from inside the class itself with:stageRef.addChild(this)createLevel class is used to generate a 11x15 sized grid and also have one container named blockHolder that holds the grid pieces.hat I am trying to do is I cant reach the creteLevel's blockHolder object from Player Object. I am also adding some related code below:Document Class:
PHP Code: private var oPlayer:Player; private var oLevel:CreateLevel;
I am trying to use a new script that uses XML to dynamically create a menu on the stage. Within the XML, I am establishing a function to use with that button. One button may just link to something on the web while another will simple display/hide a specific movieclip on the stage. I also have another button that I need to use to show any hotspots on the stage. Originally, I had the code on the instance of a static button on the stage and used a loop to get the items on the stage. Now, though, I have this "generic" Object() with a function called showHot. I have been playing around with using _parent, but can't figure out how to get to the items on the stage. All my hotspot movieclips' names start with "hs", so if I can just figure out how to loop through the items on the stage, I can check the names of those items.