accessing property of child of a display object


i need some help to understand how to access a property of a child of a DisplayObject.

within a class i have an object with the variable name: btnLMain
i have assigned it a name property: btnLMain.name = "btnLMain";
btnLMain also has a property: btnLMain.clickNum = 0; // thats the one i need to access
when i instantiate the class (btnL) containing this code in the parent class i need to access the property "clickNum" so i did this:

var dispObj:DisplayObject = btnL.getChildByName(btnLMain);
displayObj.clickNum++;

but then i get the error: 1119: Access of possibly undefined property clickNum through a reference with static type flash.display:DisplayObject.

so then i reviewed documentation and from what i understand i am not able to access the property of the child of the DisplayObject as it is a static property... please correct me if i'm wrong.

so now i am trying to figure out how to access that property in the child Class.

do you have any advice for me

Posted On: Thursday 25th of October 2012 09:21:09 PM Total Views:  497
View Complete with Replies

RELATED TOPICS OF Flash / ActionScript PROGRAMMING LANGUAGE




XML: accessing all ancestors.

I am missing a way to call all xml element's ancestors like in PHP Code: element.descendants() but the other way round. Any thoughts
VIEWS ON THIS POST

176

Posted on:

Friday 12th October 2012
View Replies!

Error accessing images from XML

Code: for (var n:int = 0; n < images.length(); n++) { if (images[n].attribute("source") == event.target.name) { var thumbList = images.@source[n].parent().parent().image.@thumb; thumbLoader = new Loader(); thumbLoader.load(new URLRequest(thumbList)); thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbHandler); function thumbHandler(event:Event):void { addChild(thumbLoader); } } } I get all the URL.s of the images I want to load, but it also throws me these errors! Error opening URL Then all the URLs of the images Error #2044: Unhandled IOErrorEvent:. text=Error #2036: Load Never Completed. This dynamic XML gallery is driving me crazy! Anyone with good knowledge in building these and care to help out Ill pay if needs be! Another thing, does anyone know any good tutorials, documention or even books that cover everything about e4x /rundevo
VIEWS ON THIS POST

167

Posted on:

Friday 12th October 2012
View Replies!

loaded .swf accessing FlashVars

OK, I've got an AS3 app we'll call Game.swf, which needs to access FlashVars from Game.html... easily done with Code: LoaderInfo(this.root.loaderInfo).parameters; It turns out that Game.swf is heavy enough to require a preloader. The only effective way of doing that in AS3 is to load Game.swf into Preloader.swf, which is embedded in Preloader.html. The question is, where do the FlashVars go (in Preloader.html\t), and how can Game.swf access those variables Any suggestions on how to do this Many
VIEWS ON THIS POST

165

Posted on:

Friday 12th October 2012
View Replies!

Having trouble comprehending OOP principles of accessing objects outside of class

I'm having a bit of trouble understanding how to access objects (object instantiated from other classes) from within a class. There's so much spaghetti code to go through, right now I'm porting all timeline code in one project to different classes. What are the different ways of accessing objects or classes from within one class Don't get me wrong, I understand that you have to instantiate a class and then use its name plus the dot character to access any properties, but sometimes I get confused and would just like a simple explanation of the best way to go about accessing objects from within a class (and not just the main class).
VIEWS ON THIS POST

165

Posted on:

Friday 12th October 2012
View Replies!

Flash running locally accessing XML

I'm having the hardest time with this. I want to test this site locally. When I publish my Flash file, it loads up the XML file just fine. When I run it in a browser, however, it doesn't load up the XML file. I've found many answers to this, sandbox, crossdomain.xml, nothing seems to be working for me. This is extremely frustrating. I just want to test it locally! The swf is being embedded into my HTML page using SWFobject. Any ideas at all\t
VIEWS ON THIS POST

225

Posted on:

Friday 12th October 2012
View Replies!

Flash arg... accessing XML Attributes name... not data

Bellow is an example senocular posted a long time ago. It's great but I am trying to figure out how to access the Attribute names so that I can build a hash from XML data, so I need to access more then just the attribute data, I need the attribute name as well. I want to be able to query the XML for the value "name" and "id". The deed output from the example bellow is: /* Output: name id */
VIEWS ON THIS POST

159

Posted on:

Friday 12th October 2012
View Replies!

External SWF - accessing the stage

This works fine in my Move but when I load this as an external movie Code: stage.addEventListener(MouseEvent.MOUSE_MOVE, moveMyMouse); the error is "Cannot access a property or method of a null object reference." How can I use the parent stage to detect the mouseevents
VIEWS ON THIS POST

176

Posted on:

Friday 12th October 2012
View Replies!

Problem with accessing AS3 vars while using google map api

I've created a google map application using AS3 that creates a map, gives it custom zoom controls and adds a custom marker to the map. I'm trying to get my custom marker to access variables on the main timeline but keep getting... TypeError: Error #1034: Type Coercion failed: cannot convert com.google.maps.wrappers::WrappableComponent@2022b d81 to flash.display.MovieClip. at marker/frame1() Has anyone had any experience with this problem I've tried everything I could think of for accessing the variables from inside the MovieClip to sending the variables from the main timeline with no success.
VIEWS ON THIS POST

170

Posted on:

Friday 12th October 2012
View Replies!

Problems with dispatchEvent and with accessing a netStream object inside custom class

Hej Guys! I currently work on a simple VideoObject class. This class extends Sprite. The constructor takes 3 parameters: the filename of a .flv, width and height of the video. The class does all the netConnect and netStream stuff to load the video and add it to its displayList. My goal is that I can finally simply create a new VideoObject wherever I want, supply the 3 parameters and get the reference to a sprite containing a connected, streaming and paused video. Then I could for example place the VideoObject somewhere on the stage and resume playing or seek or whatever. I hope that's understandable so far. Basically my class works. But I still encounter a bigger and a minor problem: The bigger problem: As you can see in the code below, I create a netStream inside my VideoObject class called ns as a public property. But when I try to access the netStream Object through an instance of my VideoObject, I get an error telling me that I try to access a null object reference. Tracing myVideoObject.ns returns null as well. Now what could be the problem I mean, I should be able to access the netStream object from outside the class as well, right The smaller problem: I try to dispatch a custom event when the video is ready and listen for the event from outside the class (see .fla code). The event gets dispatched but so far I have not been able to receive it. Any ideas would be highly appreciated! Here comes the class: PHP Code: package{ \t\timportflash.display.Sprite; \t\timportflash.events.Event; \t\timportflash.events.NetStatusEvent; \t\timportflash.events.SecurityErrorEvent; \t\timportflash.events.AsyncErrorEvent; \t\timportflash.media.Video; \t\timportflash.net.NetConnection; \t\timportflash.net.NetStream; \t\tpublicclassVideoObjectextendsSprite{ \t\t\t\tpublicvarvideoURL:String; \t\t\t\tpublicvarvideoWidth:int; \t\t\t\tpublicvarvideoHeight:int; \t\t\t\tpublicvarns:NetStream; \t\t\t\tpublicvarvideo:Video; \t\t\t\tprivatevarnc:NetConnection; \t\t\t\tprivatevarmyEvent:Event; \t\t\t\t \t\t\t\tpublicfunctionVideoObject(videoURL:String,videoWidth:int,videoHeight:int) \t\t\t\t{ \t\t\t\t\t\tthis.videoURL=videoURL; \t\t\t\t\t\tthis.videoWidth=videoWidth; \t\t\t\t\t\tthis.videoHeight=videoHeight; \t\t\t\t\t\tinit(); \t\t\t\t} \t\t\t\t// \t\t\t\t//initialize \t\t\t\tprivatefunctioninit():void \t\t\t\t{ \t\t\t\t\t\tmyEvent=newEvent("video_loaded"); \t\t\t\t\t\t \t\t\t\t\t\tnc=newNetConnection(); \t\t\t\t\t\tnc.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler); \t\t\t\t\t\tnc.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityErrorHandler); \t\t\t\t\t\tnc.connect(null); \t\t\t\t} \t\t\t\t// \t\t\t\t//checknetworkconnectionandproceedifsuccessfull \t\t\t\tprivatefunctionnetStatusHandler(event:NetStatusEvent):void \t\t\t\t{ \t\t\t\t\t\tswitch(event.info.code){ \t\t\t\t\t\t\t\tcase"NetConnection.Connect.Success": \t\t\t\t\t\t\t\t\t\tconnectStream(); \t\t\t\t\t\t\t\t\t\tbreak; \t\t\t\t\t\t\t\tcase"NetStream.Play.StreamNotFound": \t\t\t\t\t\t\t\t\t\ttrace("Unabletolocatevideo:"+videoURL); \t\t\t\t\t\t\t\t\t\tbreak; \t\t\t\t\t\t} \t\t\t\t} \t\t\t\t// \t\t\t\t//beginvideostreaming \t\t\t\tprivatefunctionconnectStream():void \t\t\t\t{ \t\t\t\t\t\tvarns:NetStream=newNetStream(nc); \t\t\t\t\t\tns.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler); \t\t\t\t\t\tns.addEventListener(AsyncErrorEvent.ASYNC_ERROR,asyncErrorHandler); \t\t\t\t\t\tvarvideo:Video=newVideo(); \t\t\t\t\t\tvideo.attachNetStream(ns); \t\t\t\t\t\tns.play(videoURL); \t\t\t\t\t\tns.pause(); \t\t\t\t\t\t \t\t\t\t\t\tvideo.width=videoWidth; \t\t\t\t\t\tvideo.height=videoHeight; \t\t\t\t\t\tvideo.x=-videoWidth/2; \t\t\t\t\t\tvideo.y=-videoHeight/2; \t\t\t\t\t\taddChild(video); \t\t\t\t\t\t \t\t\t\t\t\tdispatchEvent(myEvent); \t\t\t\t} \t\t\t\t// \t\t\t\t//handlesecurityerrors \t\t\t\tprivatefunctionsecurityErrorHandler(event:SecurityErrorEvent):void \t\t\t\t{ \t\t\t\t\t\ttrace("securityErrorHandler:"+event); \t\t\t\t} \t\t\t\t// \t\t\t\t//handleasyncerror \t\t\t\tprivatefunctionasyncErrorHandler(event:AsyncErrorEvent):void \t\t\t\t{ \t\t\t\t\t\t//ignoreAsyncErrorEventevents. \t\t\t\t} \t\t} } and here is the .fla where I create a videoObject and listen for my event: PHP Code: varmyVideo:VideoObject=newVideoObject("test.flv",720,405); myVideo.x=stage.stageWidth/2; myVideo.y=stage.stageHeight/2 addChild(myVideo); trace(myVideo.ns); myVideo.ns.resume(); myVideo.addEventListener("video_loaded",onVideoLoaded); functiononVideoLoaded(event) { \t\ttrace("videoloaded"); }
VIEWS ON THIS POST

174

Posted on:

Friday 12th October 2012
View Replies!

Problem(I think...) accessing instance objects.

First up, my first post here, so hi to all. Ok the problem I've got isn't really a bug, I mean the code does what I want so far, but I think I might going about it the wrong way. Simple game, a breakout clone in AS3, although this time I was messing about splitting it up into classes, but was having trouble accessing instances of those classes... Way I got around it was to... add them to arrays... example, creating an instance of a menu... Code: var menuItem = new MainMenu(); menuArray.push({aButton:addChild(menuItem.createStartBtn())}); menuArray.push({aButton:addChild(menuItem.createOptionBtn())}); // some time later menuArray[0].aButton.x = 10; That cant be right though can it I mean I was ok with it when I was sticking instances of blocks and player paddle etc into arrays, but now sticking the menu screen into an array Is there a better way of accessing them, other then adding them to an array like thatOr am I just worrying about nothing EDIT: Well, doesn't look like I'm going to get a reply to this thread... but no worries, I found a better solution, for anyone else who might suffer a brain fart like I did and finds this, make the external class return an object, and in the main class be sure to have an object variable handy ( var bla:Object; ), just assign the returned object to that, no need for arrays. If object variable has scope, no problems accessing it form anywhere else.
VIEWS ON THIS POST

202

Posted on:

Friday 12th October 2012
View Replies!

Help with Senocular's TopLevel class accessing stage

, Hope your Sundays is going well Mine isn't.. I;ve been struggling with Senocular's TopLevel class usage. A quick overview is that my Document Class extends TopLevel and makes th static variables (as per Senocular's post) and then I have some remoting classes that fetch things from my database. I can use the TopLevel to access [object Stage] but when I try to access anything on that it just says '1119: Access of possibly undefined property HB1 through a reference with static type flash.display:Stage' compile-time error - this is when using Code: trace(TopLevel.stage.HB1); I also tried Code: var TL = TopLevel.stage; trace(TL.HB1); which gives me "ReferenceError: Error #1069: Property HB1 not found on flash.display.Stage and there is no default value. at Remoter/::healthUpdate()" Run-time error. AM i missing some interim property that stores the actual objects There is an instance of the target on the stage with instance name of "HB1" and I can access it from the Document Class with just "trace(HB1);" I can't just pass a reference directly, and I can't find anyone with issues regarding Senocular's code, so I guess I'm just missing something. the describeType() result for the TopLevel.stage (called from non-document class) doesn't enlighten me, lots of properties but none seem to relate to much. Any help gratefully received! Edit: I have also tried playing with the linkages but didn't entirely understand what it meant, so left it with nothing ticked, but none of the settings seemed to help.
VIEWS ON THIS POST

223

Posted on:

Friday 12th October 2012
View Replies!

class vs. instance: accessing public methods

I have a Segment class and instances of the segment class. Public functions called from the class itself fail, where functions called from instances work. Example: Code: import Scripts.Segment; // my class import flash.geom.Point; var p1:Point = new Point(1, 3); var p2:Point = new Point(7, 4); var p3:Point = new Point(4, 5); var p4:Point = new Point(5, 1); var mySegment1:Segment = new Segment(p1, p2); // generate two instances var mySegment2:Segment = new Segment(p3, p4); var p5:Point = mySegment1.intercept(mySegment1, mySegment2); // works var p6:Point = Segment.intercept(mySegment1, mySegment2); // gives me an error Error looks like this, by the way: 1061: Call to a possibly undefined method intercept through a reference with static type Class. How do I access the methods without using an instance Like the way one might use Point.distance(p1, p2)
VIEWS ON THIS POST

216

Posted on:

Friday 12th October 2012
View Replies!

problem with accessing sub movieclip's textfields' properties in different frames

hi. i have a movieclip called rootmc in the root timeline (frame 1) and there is a 10 frame in rootmc and 10 sub mc in every frame. and there are text fields in sub mc's. like this: rootmc / mc1 (in frame1 of rootmc) / txt1 (frame 1 of mc1) rootmc / mc2 (in frame2 of rootmc) / txt2 (frame 1 of mc2) rootmc / mc3 (in frame3 of rootmc) / txt3 (frame 1 of mc3) . . . i want to restrict textfield with "0-9" and "." but i have to type every 10 frame in rootmc's to restrict like this code: mc1.text1.restrict = "0-9\\."; mc2.text2.restrict = "0-9\\."; mc3.text3.restrict = "0-9\\."; . . . how can i do this in rootmc frame 1 to restrict textfields only one frame code sorry for bad english.
VIEWS ON THIS POST

197

Posted on:

Tuesday 16th October 2012
View Replies!

Help with accessing dynamically gen mc from a class (code included).

Hi all hope you had good holidays! Hope you can help. I have a doc class(main) and a mc with linkage (follower class). Basically its a mouse follower that i want as a class. But am getting this error: Main class has been instantiated correctly TypeError: Error #1009: Cannot access a property or method of a null object reference. at follower() at main() I have class inst in doc class via:- var mouse:follower = new follower(); addChild (mouse); Here is the follower class:- package { import flash.display.MovieClip; import com.greensock.TweenLite; import com.greensock.TweenMax; import flash.events.Event; import flash.ui.Mouse; import flash.events.MouseEvent; public class follower extends MovieClip { public function follower() { // constructor code //Listen when the mouse moves stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoves); //This function is called when the mouse moves function mouseMoves(e:Event):void { //Tween the follower movie clip to the cursor's coordinates TweenMax.to(this, 0.5 ,{x :mouseX, y: mouseY}); } //Call the function which tween various properties of the follower up(); //This function adds more blur and scales the follower function up():void { //Tween the blur TweenMax.to(this, 0.5, {blurFilter:{blurX:15, blurY:15}}); //Tween the scale and call the function down() when finished TweenMax.to(this, 0.5, {scaleX: .75, scaleY: .75, onComplete: down}); } //This function removes blur and scales the follower function down():void { //Tween the blur TweenMax.to(this, 0.5, {blurFilter:{blurX:10, blurY:10}}); //Tween the scale and call the function up() when finished TweenMax.to(this, 0.5, {scaleX: 0.5, scaleY:0.5, onComplete: up}); } } } } many
VIEWS ON THIS POST

241

Posted on:

Tuesday 16th October 2012
View Replies!

accessing properties of movie clip

I have the following prob : I created several instance of the same MC like this ActionScript Code: for (j=0; j
VIEWS ON THIS POST

166

Posted on:

Wednesday 17th October 2012
View Replies!

CS3 Problem accessing data loaded from external textfile.

Hi , I'm trying to load data from an external textfile, called "config_flash.txt". It works perfectly if applying the fetched data is done within the same function where the loading is done. However, I would like to use the fetched variables in other parts of the script. Here's what works: Actionscript Code: var varLoader:URLLoader = new URLLoader(new URLRequest("config_flash.txt"));varLoader.addEventListener(Event.COMPLETE, completeConfiguration);function completeConfiguration(event:Event):void { var loadedVars:URLLoader = URLLoader(event.target); var variables:URLVariables = new URLVariables(loadedVars.data); var text1:String = variables.text1; var text2:String = variables.text2; myTextfield.text = text1 + " " + text2;} Here's what I want: Actionscript Code: var varLoader:URLLoader = new URLLoader(new URLRequest("config_flash.txt"));varLoader.addEventListener(Event.COMPLETE, completeConfiguration);function completeConfiguration(event:Event):void { var loadedVars:URLLoader = URLLoader(event.target); var variables:URLVariables = new URLVariables(loadedVars.data); var text1:String = variables.text1; var text2:String = variables.text2;}myTextfield.text = text1 + " " + text2; So, basically I want the variables/values defined inside the function to be available anywhere in the script. The error that the second code snippet causes is as follows: "1120: Access of undefined property text1/text2". I have a feeling that this has a very simple solution, but I'm not so good with this whole code jargon world .
VIEWS ON THIS POST

218

Posted on:

Thursday 18th October 2012
View Replies!

problem in accessing cookie with flash in IE

I want to write a Flash application which need to access my browser(Internet Explorer) cookie. My program work well in all browser except Internet Explorer. This is part of my code: Code: Quote: function test() { ExternalInterface.call("eval","alert(document.cook ie)"); } What is the problem with Internet Explorer
VIEWS ON THIS POST

144

Posted on:

Friday 19th October 2012
View Replies!

accessing properties and methods of an external swf

I've read through about 100 posts on this subject, but none seem to fit my situation. I can't access the props and methods of an external AS3 swf after it's loaded by Main.as. Here's a very simplified version of the code for Main.as (the calling swf): Code: package{ import flash.display.Sprite; import flash.events.Event; import flash.net.URLRequest; import flash.display.Loader; public class Main extends Sprite{ private var imgLoaded:Boolean = false; private var imgLdr:Loader; private var contentSWF:Sprite; public function Main(){ loadSWF(); } public function loadSWF():void { imgLdr = new Loader(); var urlReq:URLRequest = new URLRequest("Sub.swf"); imgLdr.load(urlReq); imgLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler); } private function onCompleteHandler(event:Event):void{ event.currentTarget.removeEventListener(Event.COMPLETE, onCompleteHandler); contentSWF = event.currentTarget.content; addChild(contentSWF); trace(contentSWF.testBool); // This throws the following error: // 1119: Access of possibly undefined property testBool // through a reference with static type flash.display:Sprite. } } } Here's the code for Sub.as (the external swf): Code: package{ import flash.display.Sprite; import flash.events.Event; public class Sub extends Sprite{ private var _testBool:Boolean = false; public function Sub(){ init(); } private function init():void{ testBool = true; } public function get testBool():Boolean { return _testBool; } public function set testBool(val:Boolean):void { _testBool = val; dispatchEvent(new Event(Event.CHANGE)); } } } Can someone please help with this
VIEWS ON THIS POST

161

Posted on:

Thursday 25th October 2012
View Replies!

accessing PHP variables within timeline

I'm struggling with some actionscript and was hoping some far more knowledgable people than myself might be able to help me I have a flash counter, it works off an integer i.e number = '12345' I'm trying to hook my counter up to a PHP script that echo's a DB query. Now I've had no issue passing the variable and I can even display it in a dynamic text field but no matter what I try I cannot get the "number" varibable to use my PHP variable The dynamic text field shows the correct value clear as day but the counter just shows "undefined". The code is below with comments if anyone could point me in the right direction I would appreciate it so much! ActionScript Code: //create a new "LoadVars" object myLoadVar = new LoadVars (); //load the contents of the text file into the LoadVars object myLoadVar.load("somedomain dot com somescript.php"); //check to see if the loading is completed and, if so, put the contents in the text field myLoadVar.onLoad = function (success){ if (success == true) { // the 'seats' text field gets successfully populated with var here seats.text = myLoadVar.myCount; } } // this doesn't work number = myLoadVar.myCount // this does work though number = '12345' Many
VIEWS ON THIS POST

160

Posted on:

Thursday 25th October 2012
View Replies!

URLLoader accessing XML from an API

I'm writing a simple class that will be used to access data from an API takes XML queries and returns the data in an XML format. In my main document class I import the API class "import API;" then am accessing various methods of my class to access different calls to the API (var myAPI:API = new API();, then API.method() ) My main questions are: 1. With the URLLoader having a delay, I suppose there is no way in my main class to return data to the original call via a return statement( myXMLData = API.getSomeData() ). Basically, how do I write a generic "onComplete" function such that it knows which method in the class called it, where to store the data, and how to tell the original call in the document class that the load is complete and to begin using the data Here is the code for my class so far: Code: package { import flash.display.Sprite; import flash.events.Event; import flash.events.IOErrorEvent; import flash.net.URLLoader; import flash.net.URLRequest; import flash.net.URLRequestMethod; public class API extends Sprite{ const DEV_KEY:String = "***"; var xmlResponse:XML; public function API() { } private function sendRequest(xmlData:String):void { var xmlDataEncoded:String = escape(xmlData); var xmlSendLoad:URLLoader = new URLLoader(); trace("sending: " + xmlDataEncoded); xmlSendLoad.addEventListener(Event.COMPLETE, onComplete, false, 0, true); xmlSendLoad.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true); xmlSendLoad.load(new URLRequest("192.168.1.120/game/api.plxml=" + xmlDataEncoded)); } private function onComplete(evt:Event):void { try { xmlResponse = new XML(evt.target.data); trace("Response: " + xmlResponse); removeEventListener(Event.COMPLETE, onComplete); removeEventListener(IOErrorEvent.IO_ERROR, onIOError); } catch (err:TypeError) { trace("An error occured when communicating with server:\n" + err.message); } } private function onIOError(evt:IOErrorEvent):void { trace("An error occurred when attempting to load the XML.\n" + evt.text); } public function getAPIVersion():void { sendRequest(""); } public function getSeason():void { sendRequest(""); } public function getUser(user:String, pw:String) { sendRequest(""); } public function getPlayerList(user:String, pw:String) { sendRequest(""); } } }
VIEWS ON THIS POST

152

Posted on:

Thursday 25th October 2012
View Replies!