Access a var inside a child MC

I'm new to AS3 and have a movie clip on the stage that contains a var,

the MC is called "myMC"
ie Code: var path = "my path";//this is in the first frame of myMC I want to access this value from the parent element, in this case it is the stage.

So on the first frame on my stage i have,
Code: trace(myMC.path);// this returns underfined This would work in AS2.

Can i access this or do i need to create a class to access vars of a child

Posted On: Thursday 25th of October 2012 10:51:20 PM Total Views:  302
View Complete with Replies

Related Messages:

How to access the class using code on first frame of the layer?   (91 Views)
The following class works fine when calling it through document properties panel. How can I access the same by writing code (to call the class) in first frame of my project The following is the Class (Code): Code: /* Main Class */ /* Developed by Carlos Yanez */ /* Image: */ package { import flash.display.MovieClip; import; import flash.utils.Timer; import; public class Snow extends MovieClip { private var flakesVector:Vector. = new Vector.(); private var timer:Timer = new Timer(2000); public function Snow(speed:int = 3, flakesNumber = 150):void { for(var i:int = 0; i < flakesNumber; i++) { var flake:Snowflake = new Snowflake(); flake.vel = (Math.random() * speed) + 0.5; flake.xSpeed = Math.floor(Math.random() * (0.5 - -0.5 + 1)) + -0.5; flake.scaleX = (Math.random() * 1) + 0.3; flake.scaleY = flake.scaleX; flake.x = Math.random() * stage.stageWidth; flake.y = Math.random() * stage.stageHeight; addChild(flake); flakesVector.push(flake); } addEventListener(Event.ENTER_FRAME, fall); timer.addEventListener(TimerEvent.TIMER, changeMovement); timer.start(); } private function fall(e:Event):void { for(var i:int = 0; i < flakesVector.length; i++) { flakesVector[i].x += flakesVector[i].xSpeed; flakesVector[i].y += flakesVector[i].vel; if(flakesVector[i].y > stage.stageHeight) { flakesVector[i].x = Math.random() * stage.stageWidth; flakesVector[i].y = -flakesVector[i].height; } } } private function changeMovement(e:TimerEvent):void { for(var i:int = 0; i < flakesVector.length; i++) { flakesVector[i].xSpeed *= -1; } } } } Please help. The following code throws an error: Code: import Classes.Snow; var snow:Snow = new Snow(); snow.init(50, 10, 5, 1200, 800, "left"); addChild(snow); The error is: 1061: Call to a possibly undefined method init through a reference with static type Snow.
How can I access the movie Clip using button?   (102 Views)
I need the following: Using Flash CS4 AS3. 1) GoUp (GoUp is a button to move a square (Box_mc) up) 2) Once it is go up the button label of GoUp to be changed to "GoDown" 3) DoDown (GoDown is a button to move down the square (Box_mc) 4) Once it is go down, the button lablel again to be changed "GoUp" Just like toggle between GoUp & GoDown buttons. Note: The Square (Box_mc) is on the same form since there is only one layer.
Flash How to access a local database using AS3   (91 Views)
Hi , I've been looking a lot in the web on how to do this, but i'm kinda short on time right now so decided ask help from you instead. So i have this simple project i have to make in flash banner that consists of 3 buttons and everytime i click that button, its going to show its respective image. But the thing is the image is not going to be part of the fla. The image is in a local database and i was wondering if there is a way to access that local database without using any php Hope i'm making sense on this.
Flash Error #1009: Cannot access a property or method of a null object reference.   (288 Views)
I dont understand these errors or how to fix them. Code: TypeError: Error #1009: Cannot access a property or method of a null object reference. at Function/Levels/$construct/createLvl()[C:\Users\Owner\Desktop\Flash AS3\Platform Game\Classes\] at Levels()[C:\Users\Owner\Desktop\Flash AS3\Platform Game\Classes\] at DocumentClass()[C:\Users\Owner\Desktop\Flash AS3\Platform Game\Classes\] DocumentClass: Code: package { import flash.display.MovieClip; import flash.ui.Keyboard; import; import; import flash.utils.Timer; import; import Classes.Levels public class DocumentClass extends MovieClip { public var gameTimer:Timer; private var LevelActionScript; public var character:Character; public function DocumentClass() { character = new Character(); addChild( character ); LevelActionScript = new Levels(); LevelActionScript.Levels(); /*gameTimer = new Timer(500); gameTimer.addEventListener( TimerEvent.TIMER, CharacterMovement ); gameTimer.start(); }*/ var leftKeyDown:Boolean = false; var upKeyDown:Boolean = false; var rightKeyDown:Boolean = false; var downKeyDown:Boolean = false; var mainSpeed:Number = 7; var mainJumping:Boolean = false; var jumpSpeedLimit:int = 15; var jumpSpeed:Number = jumpSpeedLimit; character .addEventListener(Event.ENTER_FRAME, moveChar); function moveChar(event:Event):void { if (leftKeyDown) { character.x -= mainSpeed; } if (rightKeyDown) { character.x += mainSpeed; } if (upKeyDown || mainJumping) { mainJump(); } } stage.addEventListener(KeyboardEvent.KEY_DOWN, checkKeysDown); function checkKeysDown(event:KeyboardEvent):void { if (event.keyCode == 37 || event.keyCode == 65) { leftKeyDown = true; } if (event.keyCode == 38 || event.keyCode == 87) { upKeyDown = true; } if (event.keyCode == 39 || event.keyCode == 68) { rightKeyDown = true; } if (event.keyCode == 40 || event.keyCode == 83) { downKeyDown = true; } } stage.addEventListener(KeyboardEvent.KEY_UP, checkKeysUp); function checkKeysUp(event:KeyboardEvent):void { if (event.keyCode == 37 || event.keyCode == 65) { leftKeyDown = false; } if (event.keyCode == 38 || event.keyCode == 87) { upKeyDown = false; } if (event.keyCode == 39 || event.keyCode == 68) { rightKeyDown = false; } if (event.keyCode == 40 || event.keyCode == 83) { downKeyDown = false; } } function mainJump():void { if (! mainJumping) { mainJumping = true; jumpSpeed = jumpSpeedLimit * -1; character.y += jumpSpeed; } else { if (jumpSpeed < 0) { jumpSpeed *= 1 - jumpSpeedLimit / 75; if (jumpSpeed > - jumpSpeedLimit / 5) { jumpSpeed *= -1; } } if (jumpSpeed > 0 && jumpSpeed = stage.stageHeight - character .height) { mainJumping = false; character.y = stage.stageHeight - character.height; } } } } } } Levels: Code: package { import flash.display.Sprite; import flash.display.MovieClip; public class Levels extends MovieClip { public var character:Character; //LEVEL VARIABLES //the current lvl var lvlCurrent:int = 1; /*The key for the level arrays: 1: Regular Block X: Main Character */ //this variable will hold the character var X:String = 'MAIN'; //the array for level 1 var lvlArray1:Array = new Array( 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,X,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 ); public function Levels() { character = new Character(); //creating the level //this guy will hold all of the blocks var blockHolder:Sprite = new Sprite(); //then we add him to stage //current row that we are creating var row:int = 0; addChild(blockHolder); function createLvl():void { //getting the current level that we are on var lvlArray:Array = MovieClip(root)['lvlArray' + lvlCurrent]; //we have to find how far this level goes //this will be used so we know when to move to the next row //there will always be 16 rows, so this is how we find it out //of course, this will make the lvl formatting very strict var lvlColumns:int = Math.ceil(lvlArray.length / 16); //now we must create the level for (var i:int = 0; i
accessing textbox   (109 Views)
I have a 2D array that creates a table with value that contain sum of 2 dices. but I want the result of the dice roll display on the appropriate text box on the table. I'm stuck at getting position of textbox which shown at bottom code where I have it as that position as now. selec is the instance name of those textbox. I have attach the source file as well, hopefully someone can help me with this, thank you Code: var row:int=7; var colum:int=7; var dicechar:Array=new Array(); var reddice:int var whitedice:int var textboxarray:Array=new Array(); whitedice=Math.random()*6+1 reddice=Math.random()*6+1 for(var i:uint=1;i
Cannot access parent Movieclip   (100 Views)
all. I have a function that loads the movieclips from the library. Code: // Declaring variables to the objects from the library var obj1:DisplayObject = new apresentacao(); var obj2:DisplayObject = new conceito(); var obj3:DisplayObject = new marca(); var obj4:DisplayObject = new papelaria(); var obj5:DisplayObject = new comparativo() loadContent(obj1); var activeSection:DisplayObject; function loadSection(section:DisplayObject){ activeSection = section; content.addChild(section); } But i CAN'T access the timeline where the code is from the instantiated movieclip (obj, obj2, whatever it is); inside "apresentacao" movieclip I've tried to trace the parent and i get NULL. Why
#1009: Cannot access... Sprite/Child... ???   (320 Views)
I have button is scroolbar. I can link it with: scrooll_mc.content_mc.five.addEventListener(MouseE vent.CLICK, clickFive); function clickFive(evtObj:MouseEvent){ trace("uz triju bt") gotoAndStop("antras"); } But the problem comes when I go to link of that button and come back it doesnt work. Flash gives an error: #1009: Cannot access a property or method of a null object reference. at bandymai_fla::MainTimeline/frame1() at flash.display::Sprite/constructChildren() at flash.display::Sprite() at flash.display::MovieClip() at flash.display::Sprite/constructChildren() at flash.display::Sprite() at flash.display::MovieClip() at bandymai_fla::scrollMkkkC_1() at flash.display::MovieClip/gotoAndStop() at bandymai_fla::MainTimeline/clickSection() Im a little lost now, maybe anybody can help with that
How to loaded external SWF access "local" Stage ?   (86 Views)
Hi! I doing a project which I need to load a SWF form another host, into a SWF on my host. Ex.: >> loading >> http://faraway/loaded.swf But I have problems when it finishes loading, because loaded.swf try to access Stage to watch for it's dimensions, I get some security error. "SecurityError: Error #2070: Security sandbox violation: loaded.swf cannot access Stage owned by loader.swf." What can I do to solve that
how do i access a function in the main class from another class?   (79 Views)
i am new to as3. i have a game that i want to put load screen on, which i created a separate class for. first the main class is initialized and in the constructor function, it does an addChild(loadScreen) which places an instance of the loadScreen MC on the stage. within the loadScreen is a "Play Button" that when a user presses this button i want it to continue startGame in the Main class. the way i tried it was Main.startGame from the loadScreen class, but that obviously does not work. is it possible to call a function from a different class, or is there just a simpler way of doing this that i am missing i have three files: Main.fla the file: Code: package { import flash.text.*; import flash.display.*; import*; public class Main extends Sprite { var startPage:loadScreen = new loadScreen(); public function Main() { addChild(startPage); } public function startGame() { // The meat of the code for the game is here } } } the file: Code: package { import flash.text.*; import flash.display.*; import*; public class loadScreen extends MovieClip { public function loadScreen() { bLoad.buttonMode=true; bLoad.addEventListener(MouseEvent.CLICK,playGame); } public function playGame(e:MouseEvent) { Memory.startGame(); //
access buttons inside movie clip   (88 Views)
I've got some buttons in a movie clip called myContent. myContent is in the library, it is being exported for actionscript, and then referenced by a scrollpane component on the main stage. The idea is that there is a scroll pane with buttons in it, each button loads a video (from a folder called FLV) on the FLVplayer component (instanced 'vidPlayer') on the main stage. For some reason the buttons are unresponsive when I publish the movie. the scrollpane loads up ok with the buttons in it, but the buttons dont load the videos they are supposed to when clicked on. no errors though. I get the feeling this is because they are inside a movie clip which is inside a scrollpane. This is an example of the script inside the myContent movie clip for one of the buttons: dance.addEventListener(MouseEvent.CLICK, vid1); function vid1(e:Event):void{ MovieClip(root).vidPlayer.source = "FLV/dance.flv" }; Do I need to add some script on the main timeline, to tell it there are buttons to look for
TypeError: Error #1009: Cannot access a property or method of a null object reference   (292 Views)
I'm new to code, and here's my problem. Any advice "TypeError: Error #1009: Cannot access a property or method of a null object reference. at type_fla::whole_1/thumbUp()" Here's my code stop(); import caurina.transitions.*; var xOffset:Number; var xMin:Number = 0; var xMax:Number = sb.track.width - sb.thumb.width; sb.thumb.addEventListener(MouseEvent.MOUSE_DOWN, thumbDown); stage.addEventListener(MouseEvent.MOUSE_UP, thumbUp); function thumbDown(e:MouseEvent):void { stage.addEventListener(MouseEvent.MOUSE_MOVE, thumbMove); xOffset = mouseX - sb.thumb.x; } function thumbUp(e:MouseEvent):void { stage.removeEventListener(MouseEvent.MOUSE_MOVE, thumbMove); } function thumbMove(e:MouseEvent):void { sb.thumb.x = mouseX - xOffset; if(sb.thumb.x = xMax) sb.thumb.x = xMax; var sp:Number = sb.thumb.x / xMax; Tweener.addTween(content, {x-sp*(content.width-masker.width)), time:1.5}); e.updateAfterEvent(); }
Can't access properties of extended abstract classes...   (112 Views)
Im building a project using an MVC pattern. I have (pseudo) abstract classes Model and View, each extended with particular models and views. But I cannot access properties on the extended classes of Model... Model simply distributes XML data, heres its constructor: Code: public function Model(data:XML) { _data = data; /*_data is a protected var of type XML in Model*/ } MainModel extends Model, and has a property called _background of type Background which also extends Model: Code: private var _background:Background = new Background(some XML source); public function MainModel(data:XML) { super(data); } public function get background():Background { return _background; } View's contstructor: Code: public function View(model:Model, controller:Controller, container:Sprite) { _model = model; /*_model is a protected var of type Model*/ _controller = controller; /*_controller is a protected var of type Controller*/ _container = _createView(container); /*_createView is an overridden method in the View Class's extended classes, _container is a protected var*/ } public function get model():Model {return _model;} MainView is a class that extends View, it has a property _bgView that also extends View: Code: private var _bgView:BgView = new BgView(model.background,controller,container) public function MainView(model:MainModel,controller:Controller,container:Sprite) { super(model,controller,container); } The problem arises when I try to pass MainModel's background property as a parameter of _bgView (highlighted in red above). The compiler says there is no background property on Model, which is true, but I need it to look at its extended class MainModel, not Model. I've typed MainView's constructor parameter with MainModel, but it is still seeing it as Model. Any suggestions would be appreciated.
Limit access to properties based on type?   (92 Views)
I have a question for any OOP experts our there: Is it possible to limit access to an object's property values based on the type of object requesting it For example: Code: public function get someValue():Type { if(the object requesting this information is the right type) { return _value; } else { trace("Sorry, you can't access this property") } }
Flex accessing objects inside an array   (110 Views)
Hi all, i have a problem accessing the objects present inside an array. For example, var array:Array=new Array(); var obj:Object = {}; var int a=1; var int b=1;var int c=1; var int d=1; for(i=0;i
Can't access button in flv skin   (98 Views)
Hi I am using a flvplayback component which I have attached to my own skin. I want to be able to target the full screen toggle button since I can't get the fullscreen to work and others posts have led me to think that it might be better to code that bit myself. For the skin fla the button that I want to get at has this written in the properties class box "" I figured I might be able to get at this from my main timeline so I added the code below : Code: stop(); function edward(event:MouseEvent):void{ trace ("the button was pressed"); }, edward); which doesn't work. It says "access of undefined property fl" - which I can kindof understand.... Anyway, what should I write please to access that button
navagiting or accessing objects added to stage   (95 Views)
I have a structure display like this: (brackets shows the depths, within their parent) my question concerns 'communication' between the highlighted objects - so you don't have to waste time understanding the whole tree! I've just added this to provide some context! mc_init (0) ___| ___mc_page (0) ______| ______rectangleBG (0) ______| ______textTitle (1) __ | ___mc_setup (1) ______| ______mc_setupBG (0) ____________| ____________mc_site (0) ____________| ____________mc_pref (1) ____________| ____________mc_edit (2) ________________| ________________text (0) ________________| ________________btn (1) Now, its easy to add a mouse event to btn(1), but how do I get this button to set the visible property (say) of 'rectangleBG(0)' So my question is how do I access the paths of these objects added to the stage any help on this would help my headache to go away! Ikonik
access class from stage MC   (148 Views)
accessing variable in document class from within another class   (82 Views)
Hi. I have an array in my doc class that I'd like to access from an external class. Can you do this and if so what's the syntax
Dyn created mc inner object access/change...   (106 Views)
Here is the scenario: I have an MC in the library (call it "MC"). It consists of 2 shapes (symbols) "MCback" and "MCframe" and dynamic TextBox "MCtext". I create 10 instances of this mc on the stage. Now I wanna go in, grab a reference to one of the instances and change ".text" of the internal dyn textBox "MCtext". I also wanna change color of the existing shapes/symbols in the mc. Now I have to be doin something wrong as Im unable to do that. Can you give me an example or point me in the right direction please... thx
stage text field access from class   (123 Views)
, A simple access from class question: I have a dynamic text field on my stage, instance name: "lives_txt" I want to populate this field from my Document class "" So in my class I have tried: parent.lives_txt.text = String (lives); where: public var lives:int = 3; I get an error: access of possibily undefined property lives_mc through a reference with static type flash.displayisplayObjectContainer. What am I doing wrong