Accessing An Array Created In One Class, From The DocClass?
Title pretty much says it all.
How can i access lets say an array called "bullets" that is stored in a class file "Turret.as", from my document class file "TestHarness.as"?
Thanks,
Gareth
ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 11-18-2007, 07:17 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Reference An Array Created In Doc Class
Hi, I need to reference an array created in doc class that consists of Navigation Movie Clip objects.
When the mouse over happens on one of those Nav Objects, I need to reference the array that I created in Doc Class.
Doc Class Code:
var newPageNav:NavButton = new NavButton(sId,sTitle,sStatus);
menuItems.push(newPageNav);
addChild(newPageNav);
Now I need to remove them from the stage:
So when the NavButton is clicked I need to go back through that array and remove items from the stage. But when I call a function from the NavButton:
public function onButtonClick(e:MouseEvent):void
{
removeSlide();
}
the function that lives in the DocClass, removeSlide()
public function removeSlide():void {
trace(menuItems.length.toString());
}
trace returns 0, saying the array doesn't exist.
Logically I understand that I am inside a NavButton class that has a handler, so even when I call removeSlide function at the Doc Class, I am still inside Nav Button Class.
So how do I get access to that array so I can remove elements from the stage.
Thank you very much for your time.
-d.
Accessing Array In Document Class From Other Classes
I've come across this problem before and I was wondering what the standard solution is as it must be a common problem:
Imagine the following:
I have a document class called 'Tree'.
This class holds an array of apples (not the actual objects, just string codes as ID for each apple).
I have another class called 'Apple'. The Tree class creates objects of these Apples. Whenever an apple is created, the string ID of the apple is added to the array.
The problem is I need to access this array from my Apple class, although it only exists in the Tree class. I'd be able to pass the array to my Apple class, but I wouldn't be able to return it. How can I do this? How can I update the array in my document class (Tree) from the Apple class? I can't create an object of the Tree class from every single apple.
Is the answer to declare the array as static and then create objects of the document class? I can't see how I can update the array without creating an object of the class.
Thankyou for any help or information you can give.
Accessing The Same Array From Stage And Class Files?
Hey all.
Ive been stuck on this for a while now, and am finding it hard to find anything on the net, because whenever i combine "array" and "class(es)" in a search it just brings stuff up about the array class lol.
What i basically want is:
enemies are created on the main timeline via actionscript, and pushed into an array.
How can i now access that array from within say a "Turret.as" class file that is controlling my turrets, to let them loop through the enemies and choose their target?
Thanks for any help,
Gareth
Help With Accessing Dynamically Created MC's
If i create 4 movie clips in the following way:
_root.attachMovie("someID","someName"+depth,depth) ;
is there any way to access them using something similar to one of the followings?:
someName[depth]._x=100;
soneName(depth)._x=100;
someName+depth._x=100;
Thanks for your help.
Accessing An MC Created Dynamically
hello:
i have a problem accessing an MC inside another MC created dynamically.
can someone help me on this?
here is my code:
Code:
first frame of _root:
for (var i=0;i<5;i++) {
var newname:String = "newnavboxmc"+i;
_root.navboxmc.duplicateMovieClip(newname,i);
_root[newname].holder_mc.bandname = "Bastard Dogs";
}
and getting the value of "bandname" using a button event:
Code:
on (release) {
trace (_root.newnavboxmc0.holder_mc.bandname);
}
it always shows an "undefined" error.
any help is very much appreciated.
thanks in advance.
[Flash 8] Referencing Class Variables From OnEnterFrame Created Within Class
Hi,
It's been a while since my last post here, but I was hoping someone could help me with a problem I'm having. I want to reference and change a class variable from within an onEnterframe function defined within a class. I can actually do this right now, but I want to do it in a different way. Here's a code sample of what I am talking about:
Test.fla file:
Code:
var t:tester = new tester()
Working tester.as file:
Code:
class tester{
private var num:Number = 100;
function tester(){
var classObj:tester = this;
var mc:MovieClip = _root.createEmptyMovieClip("test",1);
mc.onEnterFrame = function(){
trace(classObj.num); //This traces 100 (CORRECT!!!)
}
}
}
This traces 100 to the output window, just like it should
Here is the way that I would like to do it, because I want to reuse my onEnterFrame Stuff:
Code:
class tester{
private var num:Number = 100;
function tester(){
var classObj:tester = this;
var mc:MovieClip = _root.createEmptyMovieClip("test",1);
mc.onEnterFrame = this.mcOnEnterFrame;
}
private function mcOnEnterFrame(){
trace(num) //this traces undefined (BAD!!!)
}
}
As you can see, the work around to reading the class variable in the onEnterFrame function is to create a reference to the class object, before defining that function, then using the reference you created to access the class variables.
I have tried various iterations to get the second example working, but have had no luck. Does anyone know a way to get the second method working, or am I stuck using the first method.
Accessing Clips Created With AttachMovie
Hi,
I have a question as to how I would go about accessing the movie clips I'm creating with the following code:
PHP Code:
for (i=0; i<total; i++) {
_root.attachMovie("thumbButton", "thumb" + i, i);
}
This creates movie clips labeled "thumb1", "thumb2", etc. How would I go about accessing these movie clips?
IE: In the same for loop I want to call .loadMovie from each of them.
thumb1.loadMovie("images/1_gallery_1_thumb.jpg");
How do I dynamically get the 1 in there?
Accessing Dynamically Created Variables
Hey Flash Kit!
If I dynamically create Movis Clips using this process:
Code:
var str:MovieClip
for (var i=0; i<=5; i++)
{
str = new star();
addChild(str);
str.x = 550*Math.random();
str.y = 400*Math.random();
var size = 5 * Math.random();
str.width = size;
str.height = size;
}
Is there any way to access the clips individually by number afterwards?
Thanks,
DHP
Accessing Dynamically Created Controls
I have a project that dynamically creates controls based on user input. I want to be able to access these controls by name without having to drill down to the control's container. Is there a way to do that?
The following small project expresses my point:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Label;
import mx.containers.GridItem;
import mx.containers.GridRow;
import mx.containers.Grid;
import mx.controls.Alert;
private function addGrid():void
{
var g:Grid=new Grid();
var gr:GridRow;
var gi:GridItem;
var l:Label;
g.name="myGrid";
for (var i:int=0;i<2;i++)
{
gr=new GridRow();
gr.name="gr_" + i;
gi=new GridItem();
gi.name="gi_" + i;
l=new Label();
l.name="aLabel_" + i;
l.text="hey";
gi.addChild(l);
gr.addChild(gi);
g.addChild(gr);
}
myCanvas.addChild(g);
}
private function changeDynamic():void
{
/*
//I want to be able to get a handle on the label and change
//it this way.
var tmpLabel:Label=Label(myCanvas["aLabel_0"]);
tmpLabel.text="asdfasdf";
*/
//I can drill down to the label I want and change it by
//doing something like this
var g:Grid;
var gr:GridRow;
var gi:GridItem;
var l:Label;
g=Grid(myCanvas.getChildByName("myGrid"));
gr=GridRow(g.getChildByName("gr_0"));
gi=GridItem(gr.getChildByName("gi_0"));
l=Label(gi.getChildByName("aLabel_0"));
l.text="asdf";
}
private function changeStatic():void
{
//this is a label physically put on the canvas so changing
// it is no problem
this.myLabel.text="Boo";
}
]]>
</mx:Script>
<mx:Canvas x="41" y="76" width="488" height="200" id="myCanvas">
<mx:Label x="428" y="172" text="Label" id="myLabel"/>
</mx:Canvas>
<mx:Button x="380" y="460" label="Create Grid" id="myButton" click="addGrid()"/>
<mx:Button x="504" y="460" label="Change Dynamic" click="changeDynamic()"/>
<mx:Button x="666" y="460" label="Change Static" click="changeStatic()"/>
</mx:Application>
Accessing Dynamic Created Clips
I am having trouble accessing the clips for applying actions.
photAmount, thumb1xpo, thumb1ypo, sm_photo are variables.
thumbLdr is a mc holding the mc's which are created. I know they are being created as they show their respective pics. I just can't seem to apply any actions to them.
Thanks
Attach Code
var i:Number;
for (i = 1; i < photAmount; i++)
{
_root.thumbLdr.createEmptyMovieClip ("thumb" + i, i);
_root.thumbLdr["thumb" + i]._x = (i - 1) * thumb1xpo;
_root.thumbLdr["thumb" + i]._y = thumb1ypo;
_root.thumbLdr["thumb" + i].loadMovie (_root["sm_photo" + i]);
_root.thumbLdr["thumb" + i].onRelease = function(){
trace("release" + i);
};
}
Accessing Dynamically Created Movieclips
I have an application that I am adding movieclips to a container movieclip through a for loop and repeatedly calling myClip.addChild(theNewClip). Now I have a dozen clips in my container and it seems like the only way to access the clip is to use the getChildByName() method and cast it into a temporary clip so I can get at the its properties.
Is this the best and/or only way to do this? Does the old AS2 myContainer["theName"].property not work with dynamically created movieclips? It doesn't seem to work for me anymore.
Anyway I am getting the clips now, but I was hoping someone could show me a better way to access a dynamically created movie clip.
Accessing Dynamically Created Movieclips
I have an application that I am adding movieclips to a container movieclip through a for loop and repeatedly calling myClip.addChild(theNewClip). Now I have a dozen clips in my container and it seems like the only way to access the clip is to use the getChildByName() method and cast it into a temporary clip so I can get at the its properties.
Is this the best and/or only way to do this? Does the old AS2 myContainer["theName"].property not work with dynamically created movieclips? It doesn't seem to work for me anymore.
Anyway I am getting the clips now, but I was hoping someone could show me a better way to access a dynamically created movie clip.
Accessing Property Of Previously Created MC?
Hey there. Im in the beginning stages of making a shopping cart, and I just have a container mc that has a dynamic text field for the name of the item (shirtname) and qty. (shirtnum). What Im trying to do is check if the container has already been made, and if so, just increase the qty by one.
Im having trouble accessing the qty text property of the container to update it...heres my code...
Code:
var itemnum:int = 0;
function cartadd (e:MouseEvent):void
{
if (itemnum >= 1)
{
con.shirtnum.text = itemnum.toString();
}
else
{
var con:itemcontainer = new itemcontainer();
con.shirttext.text = "hello";
con.name = "con" + itemnum;
itemnum += 1;
con.shirtnum.text = itemnum.toString();
addChild(con);
}
}
The problem is in the first part of the if, my reference is wrong to con.shirtnum.text and I get a
TypeError: Error #1009: Cannot access a property or method of a null object reference.
I have also tried using getChildByName("con0").shirtnum.text = itemnum.toString(); in the beginning of my if statement.
Long story short, how do I access the shirtnum textfield once its been created?
Help Accessing Dynamical Created Instances
Heya.
With my first words i want to say sorry for my bad english because i'm from germany, so i am a bit "handycapped" writing what i want to say.
My problem :
I have created instances of a Movieclip this way :
for (i=0; i<5; i++) {
duplicateMovieClip("test", "test"+i, i);
setProperty("test"+i, _y, i*25+25);
}
The Movieclip(s) own a Textfield that i want to access. But how?
Using the pointers (_root.test+i.Label.text = "Label1") don't work.
I hope you can help me.
Thanks
Accessing SetInterval() ID Created Within A Function
All,
I am creating a text scroller and am having problems with clearInterval - the text starts scrolling, but it won't stop after I try to clear it upon a button click.
1. I declare a var (uint) equal to a setInterval() call within a function (if the text exceeds the width of the textField)
2. I have a button that "turns off" the mp3 player (swf) and resets all the text fields.
3. I can't seem to access the setInterval ID var from within the click handler.
I have declared the var (uint) at the root level, then set it to setInterval() within the function. Then I tried to access it from the click handler. I thought this would work since it's global at that point, but it doesn't.
Here's a link to the page so you can see how it doesn't work http://video.psandl.com/u.
(you have to click on the last link with the long client name)
Here's the code that's involved with this function
(of course this is only the relevant code, but I would post the fla when done for anyone who wants to use it):
Code:
//::: SCROLL DISPLAY TEXT
function scrollDisplays():void
{
(trackTextField.textWidth > trackTextField.width) ? initiateScrollTimer(trackTextField) : void;
(clientTextField.textWidth > clientTextField.width) ? initiateScrollTimer(clientTextField) : void;
}
function initiateScrollTimer(textFieldToScroll:TextField):void
{
textFieldToScroll.appendText(" ");
switch (textFieldToScroll)
{
case clientTextField:
var scrollClientTextID:uint = setInterval(scrollOneChar, 100, clientTextField);
break;
case trackTextField:
var scrollTrackTextID:uint = setInterval(scrollOneChar, 100, trackTextField);
break;
default:
break;
}
}
function scrollOneChar(textFieldToScroll):void
{
var newText:String = textFieldToScroll.text.substring(1) + textFieldToScroll.text.substr(0,1);
textFieldToScroll.text = newText;
}
/*----- TURN OFF PLAYER -----*/
function powerOff(me:MouseEvent):void
{
SoundMixer.stopAll();
loadStarted = false;
clearInterval(scrollClientTextID);
clearInterval(scrollTrackTextID);
clientTextField.text = "Make a selection below.";
trackTextField.text = "";
progressTextField.text = "0%";
clock.durTextField.text = "00:00";
tracknumTextField.text = "";
}
Thanks to anyone who can help out. I know this should be a pretty easy thing to do.
Jim
Accessing A Dynamic Text Field In A Class Other Than The Primary Class
I have tried to read and understand some of the other threads for this issue but, I think it would be easier to understand if I show my specific issue. I left some code out to make my issue more clear.
Alpha is the primary class with access to the stage. If I write the event listener and function contained in the Bravo function into the Alpha function it works. Although, I want it to be in a different class in the same package (such as the Bravo class).
I have created a instance of a class which is a physical object on the stage (lets say it's a card). The event listener is in the instance so that each instance has a self contained listener.
The bottom line is it works in the primary class but in no others. How can I make it access the text field (so when I click on the "card" the text field shows "something"?
ActionScript Code:
package a {
public class Alpha {
public function Alpha() {
x:Bravo = new Bravo();
}
}
}
package a {
public class Bravo {
public function Bravo() {
this.addEventListener(MouseEvent:CLICK, clickEvt);
function clickEvt(event:MouseEvent) {
<MovieClip>.<MovieClip>.<DynamicTextField>.text = "something";
}
}
}
}
Button Created Within Class Cannot Access Class Properties
Hi,
I'm using the following code within a class:
code:
_head_mc.attachMovie("headButton", "head_btn", this.getNextHighestDepth());
_head_mc.head_btn.onRelease = function () {
containingClip_mc._parent._parent.clickedHead(_per sonName);
}
The button gets attached (line 1). This works because I can see the mouse changing to a finger.
The onRelease function is declared and works. I know because if I put a trace in there, it works.
The function it calls (containingClip_mc._parent._parent.clickedHead also works, becuase I can see traces from within it.
But the _personName variable is passed as undefined.
I know that this variable has a value, because I can trace it outside the function, but it seems that this onRelease function is not able to see the variable. It's declared as private, but setting it to public doesn't fix anything.
I imagine there's something I don't understand about the scoping of variables. I've tried _parent references, but that doesn't appear to help either. Is there a better way to do this or a workaround?
Barrette
Added by edit
Okay, I've pretty much determined this is a scoping issue. From the onRelease function, I'm unable to access ANY of the functions within my class. I still would like advice on how to do so..
Barrette
Accessing A Text Field That Was Created In A Function
Maybe the function has nothing to do with it. But, I create a text field in a function on frame 1 and it shows up just fine:
Code:
if (nAnswers > 1)
{
var feedback:TextField = new TextField();
feedback.x = 100;
feedback.y = 200 + ((nAnswers + .5) * 30);
feedback.multiline = true;
feedback.width = 600;
var format:TextFormat = new TextFormat();
format.font = "Arial";
format.color = 0x666666;
format.size = 12;
format.bold = true;
feedback.defaultTextFormat = format;
feedback.text = "Select an Answer";
addChild(feedback);
}
then on frame 2 I want to access that text field and change what it says:
Code:
feedback.text = "New Text!"
But, I keep getting the error:
1120: Access of undefined property feedback
I see the textfield on frame 2 when I go to it, but I can't seem to change it...
What am I doing wrong?? How do I access textfields that I create on the stage?
Accessing Dynamically Created Input Textfields
Inside a function i dynamically make 10 Input textfields. How do I make them global - that is, how can I access to their .text property from outside the function? The plan is that when a user clicks on a button, the listener function will determine the values in these input textfields, but am stuck in two ways:
1) input textfields are not recognized outside the function (1120: Access of undefined property vnosno.)
2) how to access each of the 10 input textfields, when i create each one with the same variable name (is there a way to create them with successive numbers; e.g. vnosno1,vnosno2,vnosno3...?)
this is how i created the input textfields:
ActionScript Code:
for (var k:int = 0; k < 10; k++) {
var vnosno:TextField = new TextField();
vnosno.type = TextFieldType.INPUT;
vnosno.width = 100;
vnosno.height = 23;
vnosno.x = 100;
vnosno.y = 80 + (k * 30);
addChild(vnosno);
}
On Press - Accessing Buttons Created With A Loop
I have generated a series of buttons using this:
Code:
duplicateMovieClip(sign, "sign"+z, z)
while still inside the loop that is creating the buttons I can get to each sign:
Code:
_root["sign"+z]._xscale = 240;
etc.
So, once the signs are on the stage - how do I determine which sign is clicked?
Code:
on (press){
trace(this._root.sign)
}
results in this ..._level0.sign... instead of say, ..._level0.sign0...
obviously because there is no loop.
Trying to access _name does the same.
Thanks
Charles
HELP Accessing Dynamically Created Movieclips (ASAP)
i need a way to access dynamically create moviesclips made by attachMovie. I have no problems creating them but i am unable to to set any properties of the clips after they are created.. Below is an example of what i am doing.
ie
Code:
//Counter, linkX, linkY are declared in root in this example and the code is on a button, on a on release. I have the linkage to the LinkTemplate in the Actionscript
newLinkMC = "LinkMC"+-root.Counter;
attachMovie("LinkTemplateMC", newLinkMC, _root.Counter);
newLinkMC._x = _root.linkX;
_root.linkY = linkY+50;
newLinkMC._y = _root.linkY;
It creates the necessary movieclips but It will not place them in the right position. If i hard code the actually movieclip names it works but if i try to use a variable movieclip name it doesn't work... any suggestions?
Checking A Var In DocClass
Hi,
I have a public var in my DocClass.as, I need to check it from my NavClass.as which is imported into DocClass.
When I try to trace it out I comes back as undefined, but its not, I can trace it from inside my DocClass.
Basically, How can I check this var from inside my external class, I think I probably need to refrence the class in which the Var is defined but I dont know how, the Var is called 'buttonIndex' so I did,
ActionScript Code:
trace(DocClass.buttonIndex);
but I get an error...
How can I grab this Var from the DocClass ??
DocClass Preloading?
I'm having trouble trying to figure out how to apply a DocumentClass Preloader? I have no problem with timeline preloaders, but when I have nothing on stage and strictly using Actionscript to load everything I'm Lost with it? below is what I believe should work, but doesn't ??
Code:
package
{
import flash.display.MovieClip;
import com.AlfonsoMaldonado.myCalendar.Calendar2;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.text.*;
public class DocClass extends MovieClip
{
private var cal:Calendar2;
public function DocClass():void
{
// trying to add a preloader for this? NOT WORKING?
addEventListener(Event.ENTER_FRAME, myLoader);
}
private function myLoader(event:Event)
{
var bytestotal = stage.loaderInfo.bytesTotal;
var bytesloaded = stage.loaderInfo.bytesLoaded;
myText.text = ""+Math.round(bytesloaded*100/bytestotal)+"%"; // the only thing on stage
if (bytesloaded >= bytestotal)
{
removeEventListener(Event.ENTER_FRAME, myloading);
myLoader.visible=false;
startCalendar();
}
}
private function startCalendar():void
{
setStage();
cal = new Calendar2(0, 0, stage.stageWidth, stage.stageHeight);
addChild(cal)
}
private function setStage():void
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
}
}
}
thanks in advance!
Tough One: Accessing Class Methodes From Other Class Files
Tough question for the experts...
In my classfile class Classes.tools.depthManager, I've got a static methode
Code:
public static function getLoopDepth():Number {
In another classfile Classes.tools.frameRateViewer, I want to access that methode
Code:
var tempDepth = Classes.tools.depthManager.getLoopDepth();
The compiler claims: "There is no class or package with the name 'Classes.tools.depthManager' found in package 'Classes.tools'."
So I tried writing import Classes.tools.* at the top of my Classes.tools.frameRateViewer.as, hoping I could just write
Code:
var tempDepth =depthManager.getLoopDepth();
But there the compiler claims: "The class being compiled, 'Classes.tools.depthManager', does not match the class that was imported, 'depthManager'."
I'm sure the Classes.tools.depthManager.as works fine: I can call the static depthManager.getLoopDepth() from a button in the fla file...
Any ideas? Thanks!
[AS 2.0] Difficulty Accessing Dynamically Created Clips Properties.
it seems i keep bashing into really tired little problems. even after reading 5 books on AS...
the variables listHeight and maskHeight won't populate. they come up 'undefined'. what the heck am i doing wrong?! little stuff like this drives me batty!!
here's the code essence:
Code:
xml.onLoad = function(success:Boolean)
{
var stuff:Array = xml.firstChild.childNodes;
if (success)
{
createEmptyMovieClip("list", 50, {_x:10, _Y:10});
attachMovie("listMask", "mask", 52, {_x:10, _y:10});
list.setMask(mask);
for (i=0; i< stuff.length; i++)
{
counter++;
list.attachMovie("listButton", "button_"+counter, list.getNextHighestDepth(), {_x:10, _y:yPos});
yPos += list["button_"+counter]._height + 1;
}
}
}
var listHeight = list._height;
var maskHeight = mask._height;
please point me in the right direction, and provide the right kick in the head!
WR!
Accessing Document Class From Static Class?
I am building a family tree like tree in flash.
I have a package TreeManager which holds all my classes.
The document class TreeManaager.Tree controls adding new nodes to the stage.
ActionScript Code:
public function addProfile(relationship:Object):void
{
profile = new Profile();// create new profile
var align:Alignment = new Alignment();//make Alignment object
...
The profile class controls all the internal node functionality.
Question - If I have a button in my node MC (profile class) which should add a new relationship (i.e. call addProfile) how to I do this?
ActionScript Code:
public class Profile extends MovieClip {
public function Profile ():cool:
{
this.addEventListener(MouseEvent.CLICK,Tree.addProfile);
This always throws an error. I can just add the buttons events from the document class, but it would be helpful to know if you can access the document class from a packaged static class?
ActionScript Code:
// add button events
profile.mother.addEventListener(MouseEvent.CLICK,addRelationship);
profile.brother.addEventListener(MouseEvent.CLICK,addRelationship);
profile.son.addEventListener(MouseEvent.CLICK,addRelationship);
Referencing An Mc Created In One Class From Another Class
Hello everybuddy,
Cracking site, I normally don't post but have read and learned much from here thanks to all the posters!
I'm struggling with AS3 at the moment, forcing myself to take an OO approach and slowly getting there... However I'm now stuck...
My project is a dynamically generated web page, getting pics and data from xml files.
I have a button class that creates buttons based on an xml file, this is in its own class file(buttons.as) which is called from my document class.
The document class also creates a bunch of thumbnails using (screen.as), the thumbnails are placed in an MC called thumbs (which created by the document class).
What I need now is a way of linking my button class to the thumbs MC, so that when I click a button my thumbs MC is tweened using my dotween function.
when I run my project i get an errror from my buttons.as --> 1120: Access of undefined property thumbs.
I guess what i'm asking is how to reference an MC created in one class, from another seperate class. I thought that by setting it to public this would be possible but its not working...
Here is my code:
Code:
//Document.as
package {
import flash.display.MovieClip;
public class Document extends MovieClip {
public var thumbs = new MovieClip;
public var butArr = new Array;
public var screen1:screen;
public var thumbArr = new Array;
public function Document() {
//add buttons
for (var i:uint = 0; i < 10; i++) {
button[i] = new buttons(i);
addChild(button[i]);
}
//add thumb container
this.addChild(thumbs);
//addthumbs
for (var i:uint = 0; i < 10; i++) {
var thumbleft:uint=140+i*320;
thumbArr[i] = new screen(thumbleft,275,i,320,240,"thumb");
thumbs.addChild(thumbArr[i]);
}
screen1 = new screen(140,35,1,640,240,"home");
addChild(screen1);
}
}
}
Code:
//buttons.as
package {
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
import flash.display.MovieClip;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.text.*;
import flash.filters.GlowFilter;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
public class buttons extends MovieClip {
public var num:uint=1;
public var myXML:XML;
public var thisText =thisText;
public var thisID:uint = thisID;
public function buttons(thisID) {
this.num=thisID;
getXML();
}
public function getXML() {
var urXML:URLRequest;
var ulXML:URLLoader;
urXML=new URLRequest("buttons.xml");
ulXML = new URLLoader(urXML);
ulXML.addEventListener(Event.COMPLETE, xmlLoaded);
ulXML.load(urXML);
}
public function xmlLoaded(event:Event) {
myXML = XML(event.target.data);
var xmlID=thisID-1;
thisText=myXML.butTitle[this.num];
makeButton(thisText);
}
public function makeButton(thisText) {
var myTextField:TextField=new TextField;
// Here we add the new textfield instance to the stage with addchild()
addChild(myTextField);
// Here we define some properties for our text field, starting with giving it some text to contain.
// A width, x and y coordinates.
myTextField.text=thisText;
myTextField.width=120;
//myTextField.height=50;
myTextField.multiline = true;
myTextField.wordWrap = true;
myTextField.x=15;
myTextField.y=this.num*50+50;
// Here are some great properties to define, first one is to make sure the text is not selectable, then adding a border.
myTextField.selectable=false;
//myTextField.border=true;
// This last property for our textfield is to make it autosize with the text, aligning to the left.
//myTextField.autoSize=TextFieldAutoSize.LEFT;
//This is the section for our text styling, first we create a TextFormat instance naming it myFormat
var myFormat:TextFormat=new TextFormat;
// Giving the format a hex decimal color code
myFormat.color=0xFFFFFF;
// Adding some bigger text size
myFormat.size=16;
myFormat.font="SkandiaDisplay";
// Last text style is to make it italic.
//myFormat.italic=true;
// Now the most important thing for the textformat, we need to add it to the myTextField with setTextFormat.
myTextField.setTextFormat(myFormat);
this.addEventListener(MouseEvent.CLICK,changePage);
this.addEventListener(MouseEvent.MOUSE_OVER,mouseover);
this.addEventListener(MouseEvent.MOUSE_OUT,mouseout);
}
function mouseover(evt:MouseEvent):void {
var glow:GlowFilter = new GlowFilter(0xFFFFFF,0.5,5,5);
this.filters=[glow];
}
function mouseout(evt:MouseEvent):void {
this.filters=[];
}
function changePage(evt:MouseEvent):void {
var newPage:Number=evt.currentTarget.num;
trace(newPage);
//not working
//1120: Access of undefined property thumbs.
thumbs.dotween("x",700,460);
}
public function dotween(command,startVal, endVal) {
var myTween:Tween = new Tween(this,command, None.easeOut, 0, 1, 1, true);
}
}
}
Any help would be greatly appreciated!!!
Thanks in advance!
Accessing Functions In A Class, From Another Class?
is this possible?
for instance, i have a function called "registerThumb" in my main engine class which keeps a delegated array of items.
However the only time i want to call that function, is from within another class which creates the thumbnails "Thumb.as", so i can automatically register paths into the array instead of just names.
does that make any sense?
New Instance's Are Not Created From Class
Hello,
I have created a class called surverySlide in which I have linked to a bunch of slides. each slide registers how many questions it has to the class (itself). The problem is I need each movieclip to be its own instance of SurveySlide ( I have a surveyManager class built to deal with each. I am using attachmovie to show them in sequence on the stage (loading one after the other). I assumed by linking each movie clip to the class a new instance would be created each time but only one instance is created. I.e. the questions are put into an array that should be only for that instance but everytime a new instance is loaded it is added on to the array.
I don't know if I am explaining this clear enough so.....
in each instance of the class (which is a movie clip) I will register the question to that slide...
i.e.
slide instance 1
this.registerQuestion(1);
this.registerQuestion(2);
//if I output the array here I get 1,2
slide instance 2
this.registerQuestion(3);
//if I output the array here I get 1,2,3
//I want it to only output 3
Does anyone know off hand why this is happening?
StopAllSounds Created In Class
I have got 2 sounds created and started in functions in a class. When I try to stopAllSounds, it does not stop the sounds. Do I have to reference to the stop the sound inside each function? My code is attached (.as and .fla) fi somebody would be willing to help.
Cheers
otti
Attach Code
Class file:
....
// Public function to create sound for populating more ghosts.
public function addSoundGhost():Void {
// Create new sound instance for ghosts.
var soundGhost1:Sound = new Sound();
// Attach audio file to the instance.
soundGhost1.loadSound("Bloop.mp3",true);
// Start the sound instance.
soundGhost1.start();
}
//
// Public function to create sound for populating more ghosts.
public function soundColission():Void {
// Create new sound instance for ghosts.
var soundColl:Sound = new Sound();
// Attach audio file to the instance.
soundColl.loadSound("Bloop.mp3",true);
// Start the sound instance.
soundColl.start();
}
fla file:
var ghostArray:Array = new Array();
//
// Loop to push 5 ghosts into array and display.
for (var i:Number = 0; i <= 3; i++) {
ghostArray.push(new Ghost())
}
//
// Constantly move the ghosts.
this.onEnterFrame = function() {
// Loop to get all elemenst in array.
for (var j:Number = 0; j < ghostArray.length; j++) {
// Call function to move the objects.
ghostArray[j].move();
}
// Create one loop inside other loop, to get meeting arranged (constantly).
for(i:Number = 0; i < ghostArray.length; i++) {
for(j:Number = 0; j < ghostArray.length; j++) {
// Check that one ghost in the array does not meet himself.
// Call the collision function for the hitTest.
if ((i != j) && ghostArray[j].collision(ghostArray[i])) {
// trace("collision between ghost");
// change the alpha setting for instances during meeting time.
ghostArray[i].alpha(Math.random()*60+30);
ghostArray[i].soundColission();
}
}
}
}
....
// Stop all sounds
soundOffBtInst.onPress = function () {
ghostArray[i].stopAllSounds();
}
Assign Class To Created MC
Hey,
As we all know we can place an MC on stage and in the librarys linking setterings we can assign a class to it. In that class we can for exemple write this.y+=50 and the MC will move.
BUT, what happens when i create a MC by actionscript and want to assign a class to it?
Please dont answer that i should reference it by "var something:class=new class(mcName)" and use the referense to taget the mc by mcName.y+=50. Its the "this.y+=50" im looking for inside the class, not reference or targeting.
Is there any way to actually assign a class to an MC created by actionscript for real?
Thanks
Class For Dynamically Created Gears
I'm trying to create a class that will accept a number and a movieclip as parameters and create a gear that will be displayed and is movable and rotatable on the stage. I have a symbol that is a single tooth of the gear which is exported. The class should create a gear based on the number of teeth passed to it (first parameter) by duplicating and manipulating the "tooth" symbol passed to it (second parameter). It's been a long time since I tackled any actionscript coding and would appreciate any advise. I hope I've explained myself properly.
Don't Have Access From Class Created In AS File
I have a little problem
i can do somethink like this from script includet in Main Timeline:
ActionScript Code:
this.ekran.ekranText.text = "test";
But i have error when im create in AS file this script:
PHP Code:
package {
import flash.display.SimpleButton;
/**
* ...
* @author XXX
*/
public class Przycisk1 extends SimpleButton{
public function Przycisk1():void {
parent.parent.ekran.ekranText.text = "test";
}
}
}
Im on right object level - Main Timeline
This is error description:
1119: Access of possibly undefined property ekran through a reference with static type flash.display:DisplayObjectContainer.
What I should do to fix this??
Navigating Out Of An Instance Created Within A Class
Hey all,
I have a problem and I know exactly what it is but I have no Idea how to solve it. so here it goes.
I am using Penner's tween class and I am extending it to do a spacifis task. I want it to move a Clip along the y axis and then when it is done (onMotionFinished) I want it to call a method in the Class that created the instance
Code:
MPCP.applyMove = function (movObj) {
this.yMove = new Tween (this.getMosName (), 0, "_y", Math.easeOutCirc, this.getMosName ()["_y"], movObj._y, 30, false);
this.yMove.onMotionFinished = function(){
this.click()
}
}
I know for a fact that the method call (this.click()) in the onMotionFinished block is refering to the this.yMove instance. How can I call the this.click() method that belongs to my MPC Class from inside the onMotionFinished event?
Properties In A User Created Class
If I create a class and set up one property which is a variable initiated at the start of the class but not within a function or a constructor and I reference the property from the .fla in a for loop as:
Book is the class and myBook is the new object.
myBook:Book = new Book(); // (fla script).
for(var prop in myBook) {
trace(prop);
}
the .AS contains
Class Book
{
var myProp:Number = 0;
function Book() {
}
}
The trace does not return anything. However when I include myProp (the class variable) in a function (other than Book function) and call that function from the .fla then the trace works and I can see myProp.
I would be grateful if someone could explain: Do I need to include Class variables in called functions (methods of the Class) in order for them to be properties of the Class?
thanks in advance
[SOLVED] Problem "accessing" Dynamicly Created Movieclips
Hello.
I have this function which adds a bunch of MC's to the stage. This function gives them separate names but when i try to, lets say, change the alpha of one of them i get this error:
Adobe Flash CS3 Professional's Output wrote:A term is undefined and has no properties.
at index_fla::MainTimeline/frame1()
Accessing Class With Loadmovienum...
HI,
I need to build a project that will have a main.swf calling many other swf. I don't want to have to rebuild my main swf every time I change a line of code so that's why I want to have one swf that will contain all my classes(objects). So lets say I have in class.swf:
Test=function()
{
this.x=5;
this.y=7;
}
If I use loadMovieNum("class.swf",1)in call.swf, can I instantiate this?????
inst=new Test(); //doesn't work
inst=new _level1.Test();//doesn't work
Anyone have a clue?????
Thanks
Accessing Var's Outside Of A Class Instance
Hi,
I've defined a variable in my main timeline, and I want it to be accessed from inside a function inside a class, but Flash keeps throwing errors at me, how do I do this?
boombanguk
Accessing Movieclip From Within A Class
Hi I have a class on frame 1 called VTODVideo. Inside that I have a cuePoint handler which fires this when I reach a cuepoint:
code:
private function cuePointHandler(e:MetadataEvent):void
{
//trace(e.info.time);//time cuepoint was set
trace(e.info.name);//name of cuepoint
var q:VTODQuestion = new VTODQuestion(e.info.parameters.id);
}
At the time of the cue point, I create a VTODQuestion class. I am having problems accessing movieclips from within the Question class. I have a movieclip on the root of my stage named "fader" and I just want it to fade in when a question class gets instantiated. Here is my question class:
code:
package com.dop
{
import flash.display.MovieClip;
import gs.TweenLite;
import gs.easing.*;
public class VTODQuestion
{
public function VTODQuestion(questionNumber:Number)
{
trace("question number: " + questionNumber);
TweenLite.to((this.parent as MovieClip).fader,1,{alpha:1});
}
}
}
I am getting this error:
Code:
1119: Access of possibly undefined property parent through a reference with static type com.dop:VTODQuestion.
Ive tried this.parent.parent as well and no luck
Accessing Class Method
Howdy,
A bit stuck...
So you instantiate a new class like this:
Code:
var myVar:MyClass = new MyClass
And you can then access a method of MyClass like this:
Code:
myVar.myMethod()
But my problem is that I am associating a class with a linked mc in my library and attaching it to the stage at runtime, and I can't work out how to access its methods. There is no 'door' equivillant to myVar in the example above.
Please and Thanks.
Accessing Custom Class In Fla
Hello,
I seem to be the opposite of most of you. I am a long time object oriented programmer, but am VERY new to Flash. I hope this questions is not too basic, but I am having a heck of a time getting this to work.
I have a class written in ActionScript 3 (Flash cs3) in an .as file as follows:
package foo
{
public class bar{
private id:Number;
public function bar( barID:Number){
id = barID;
}
public function getID():Number{
return id;
}
}
}
It doesnt get much simpler than that i dont think.
I saved that in a projects directory in foo/bar and named the file bar.as
Then I did a file new fla (AS3) file which I saved to the same dir as the .as file, I opened the actionscript panel and I type the following:
var myBar:foo.Bar = new foo.Bar();
It chokes on that line because it cant seem to find my class. I get the error, "Type was not found or was not a compile-time constant: Foo". I even tried an import line, but it chokes on that, it just doesnt see my class. I tried also messing with the classpath stuff, but I can not seem to get this to compile.
What am I doing wrong?
Thanks,
-Savij
Accessing Functions From Doc Class?
Hey all,
Ive been tryint to use getter/setter methods on my doc class, but i just cant get it to work.
here is my doc class Main.as:
ActionScript Code:
package
{
import flash.display.*;
public class Main extends MovieClip
{
function Main()
{
}
function getTest()
{
trace("got");
}
}
}
What do i add to this class to be a ble to access it?
Player.as:
ActionScript Code:
package
{
import flash.display.*;
public class Player extends MovieClip
{
function Player()
{
//something.getTest(); ?
}
}
}
Thanks for helping,
Gareth
[OO] Accessing Parent Class...
I'm having some problems accessing a parent class with my Flash app.
My class hierarchy goes like this: I have a GameController class which contains an instance of my TeamManager class. The TeamManager class contains an array of pointers (TeamList) to different TeamMember instances.
In my TeamMember class I've set a mouse event:
PHP Code:
public function TeamMember() { this.addEventListener(MouseEvent.MOUSE_DOWN, Select);}public function Select(event:MouseEvent):void { Selected = true; }
The problem here is that once one TeamMember is selected, I want to deselect all other TeamMembers listed in TeamManager's TeamList array. I created a method in TeamManager (DeselectAll) but I can't for the life of me find a way to call it from the Select method in the TeamMember class.
Accessing Variables From Another Class
I'm new to working with multiple classes, so be gentle. I have a doc class and one other class (Input.as). I want to access a variable from Input in my doc class. I've imported the class successfully, but can't seem to access the variable. I thought I would just need to access that var by something like Input.strNum but get this error:
1119: Access of possibly undefined property strNum through a reference with static type Class.
Accessing Movieclip From Within A Class
Hi I have a class on frame 1 called VTODVideo. Inside that I have a cuePoint handler which fires this when I reach a cuepoint:
ActionScript Code:
private function cuePointHandler(e:MetadataEvent):void
{
//trace(e.info.time);//time cuepoint was set
trace(e.info.name);//name of cuepoint
var q:VTODQuestion = new VTODQuestion(e.info.parameters.id);
}
At the time of the cue point, I create a VTODQuestion class. I am having problems accessing movieclips from within the Question class. I have a movieclip on the root of my stage named "fader" and I just want it to fade in when a question class gets instantiated. Here is my question class:
ActionScript Code:
package com.dop
{
import flash.display.MovieClip;
import gs.TweenLite;
import gs.easing.*;
public class VTODQuestion
{
public function VTODQuestion(questionNumber:Number)
{
trace("question number: " + questionNumber);
TweenLite.to((this.parent as MovieClip).fader,1,{alpha:1});
}
}
}
I am getting this error:
Code:
1119: Access of possibly undefined property parent through a reference with static type com.dop:VTODQuestion.
Ive tried this.parent.parent as well and no luck
Accessing Data In A Class
Hey guys,
This question is hopefully simple. I have a class that loads an XML document and places it into an XML object. Does anyone know why I can't access that XML object from the XML that instantiates the class? I have a getter but it gets nothing. If I trace the XML object in the class it shows the XML but when I try to get it, it is blank....stumped.
Thanks.
AS2 Accessing Class Methods
Hi guys,
i created custom classes for a quiz flash im making...
in these custom classes i also attachMovie with class references
thus i have the following class hierarchy
quote:
Movie 1/Class 1
|- Movie 2/Class 2 (attachMovie)
|--Movie 3/Class 3(attachMovie)
now i have a scenario in that Class 3 needs to execute a function of class 2
So what i did is assign a variable to movie 3 with a reference in movie 2
thus in movie clip 2 when im attaching the movie clip 3 i have quote:var movie2.self = this; and movie3.clip = self;
now when im running the code and while i can
quote:
trace(clip) // outputs movie2
in movie 3
i cant seem to
[Qe]
clip.function(param);
heres a snippet of the code
Any idea whats happening here?
Attach Code
// Movie 3/ Class 3
function checkAnswer(no:Number) {
var pts:Number = getAnswer(no).pts;
if (no == correctAnswerObj.ansNo) {
pts = correctAnswerObj.pts;
}
trace(levelMc.pts); // outputs the variable's value successfully.
levelMc.updateLevel(pts); // levelMc is movie 2 with the class 2 function 'updateLevel'
// clearQuestion();
}
// Movie 2/ Class 2
function upateLevel(pts:Number):Void {
trace('ok: '+pts); // its not executing
var allAsked:Boolean = false;
var wrong:Boolean = false;
var passedLevel:Boolean = false;
if (pts == 0) {
questionsWrong++;
trace("wrong answer");
}
if ((allAsked=(noQuestion>askNoQuestions)) || ((allowedWrong != undefined) && (wrong=(questionsWrong>=allowedWrong)))) {
trace("level over");
if (allAsked) {
trace("all questions asked");
if (levelPts>totalPts) {
trace("proceed to next round");
passedLevel = true;
} else {
trace("you failed to pass this level");
}
}
if (wrong) {
trace("You got "+questionsWrong+" answers wrong");
trace("you failed to pass this level.");
passedLevel = false;
}
if (grades) {
var rank:String = undefined;
for (var i:Number = 0; i<grades.length; i++) {
if ((pts>=grades[i]['min']) && (pts<=grades[i]['max'])) {
rank = grades[i]['gradeName'];
break;
}
}
trace("Your points make you:- "+rank);
}
quiz.updateQuiz(pts,passedLevel);
} else {
trace("ready for next question");
getNextQuestion();
}
trace("level points: "+levelPts);
}
Accessing MC From External Class
Hi all. I'm just learning about external classes, so please be gentle.
I want to access a movieclip on the main timeline from an external class
(turn the MC invisible). My MC is named "mainframe"
my external class is this:
package {
public class MyClass{
public function MyClass() {
mainframe.visible=false
}
}
}
and in my fla I call it like this:
var myClass:MyClass = new MyClass();
This is the error I get:
1120: Access of undefined property mainframe.
Can someone please explain to me how to reference a movieClip on the main
timeline? I've spent 2 days looking for the answer and it's getting very
frustrating.
Thanks,
Brock
Accessing An Object Within A Class
hello all,
im kinda new to AS2.0 Classes, and im having some trouble
accessing objects within a MC's Class.
I have a MC on the timeline that has a class linked to it [the class extends MovieClip] I need the linked class to access objects within the MC, for example a text box and a few other graphics and MC's.
The class's script is : [where nav_text is a textbox located within the MC]
Code:
class NavigationDraw extends MovieClip
{
function NavigationDraw()
{
this.nav_text.autoSize = true
trace(this.nav_text._width)
}
}
How to I reference the objects? I would have throught it would be this, just as though you were referencing the text box in a frame of the MC's timeline.......
any ideas?
Thanks in Advance
|