Accessing Variables Of An XML Object In A Class File.
Hello, I have written a script to parse some xml data and now would like to use it in a .as 2.0 class file. The script works fine when I put it on frame 1 of my .fla file. However when I try to add it to my external .as class file I nolonger can grab my variables. Any variables I declare that refer to the xml object come up "undefined" by the interpeter.
Here is the method in the class file that I am speaking about:
public function loadScheduleData(){
gameCalendar = new XML(); gameCalendar.onLoad = loadCalendar; gameCalendar.ignoreWhite = true; gameCalendar.load("wildSchedule.xml"); trace(gameCalendar.firstChild); //comes up undefined
function loadCalendar(success){ if(success==true){
rootNode = gameCalendar.firstChild.childNodes; trace("well well well"); //this traces fine
var beginY=0;
var numberOfGames=gameCalendar.firstChild.childNodes.l ength;
trace(rootNode); //this traces undefined
for(i=0; i<10; i++){
container_mc.createEmptyMovieClip("textFieldContai ner"+i,i); container_mc["textFieldContainer"+i].createTextField("gameDate",101,2,2,80,25); container_mc["textFieldContainer"+i].gameDate.styleSheet = calendarStyle; container_mc["textFieldContainer"+i].gameDate.text=rootNode[i].childNodes[0]; container_mc["textFieldContainer"+i].createTextField("dayWeek",121,90,2,100,25); container_mc["textFieldContainer"+i].dayWeek.styleSheet = calendarStyle; container_mc["textFieldContainer"+i].dayWeek.text=rootNode[i].childNodes[1]; container_mc["textFieldContainer"+i].createTextField("gameTime",131,130,2,100,25); container_mc["textFieldContainer"+i].gameTime.styleSheet = calendarStyle; container_mc["textFieldContainer"+i].gameTime.text=rootNode[i].childNodes[2]; container_mc["textFieldContainer"+i].createTextField("gameTeams",141,190,2,200,25); container_mc["textFieldContainer"+i].gameTeams.styleSheet = calendarStyle; container_mc["textFieldContainer"+i].gameTeams.text=rootNode[i].childNodes[3];
container_mc["textFieldContainer"+i]._y=beginY;
beginY=beginY+20;
trace("anotherone"); //this traces fine
} } }
}
My property values are declared like this:
public var gameCalendar:XML;
private var i:Number; private var rootNode:XMLNode; private var beginY:Number; public var numberOfGames:Number;
If I put a trace statement in my loop I see the loop so I assume the xml object is loading and calling the onload function?
Any help is appreciated.
Thanks.
ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 04-10-2007, 01:26 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Accessing Root Variables From A Class File.
I have a Movie clip class named MY_MC,
and would like to access to root level variable.
fla timeline
Code:
var Status:String = "ok";
MY_MC.as
Code:
package{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class MY_MC extends MovieClip {
public function MY_MC() {
trace(Status); // here I am trying to access.
this.addEventListener(MouseEvent.MOUSE_OVER,lampOn);
}
private function lampOn(e:MouseEvent):void
{
trace("OVER");
}
}
}
How Can I do this?
Thank you.
Accessing Root Variables From A Class File.
I have a Movie clip class named MY_MC,
and would like to access to root level variable.
fla timeline
Code:
var Status:String = "ok";
MY_MC.as
Code:
package{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class MY_MC extends MovieClip {
public function MY_MC() {
trace(Status); // here I am trying to access.
this.addEventListener(MouseEvent.MOUSE_OVER,lampOn);
}
private function lampOn(e:MouseEvent):void
{
trace("OVER");
}
}
}
How Can I do this?
Thank you.
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
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
Accessing An Object On The Stage From Within A Class?
It's me again
Naah, this is a simple one. I think. If I've created a label on the stage just by sticking the code below on the first frame of the .fla:
Code:
var imgLabel:Label = new Label();
imgLabel.text = "Hello World";
imgLabel.x = 100;
imgLabel.y = 100;
stage.addChild(imgLabel);
and right below that I'm creating an instance of an image-scrolly class (that extends MovieClip) with:
Code:
var mySlideShow = new FeaturedPanel("slideshow_name");
stage.addChild(mySlideShow);
... then how the heck do you get at the label, from the image scroller thing?
I've got a function in the FeaturedPanel class that's fired when you click an image within it, with just "imgLabel.text = imgCaption;" - and it keeps telling me "Access of undefined property imgLabel."
Nuh?
Accessing Object On Stage From Class
Hi,
I'm creating a game and I want to test if an object (created by a class)
hit the main character (created on the stage)
I tried referencing the main character in the class (parent.main_character),
but it states that it doesn't recognize that instance name.
How can I reference an object on the main stage through a class?
Thanks.
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.
[F8] Accessing Variables In Custom Class
Yep... probably another scoping problem... but I can't figure it out.
I have a very simple script. I'm trying to pass a variable to a function and it's not working. Here is the code that exists inside the custom class:
Code:
public var myNumber:Number = 0;
public function testingVars(){
myNumber = 258;
trace(myNumber); // this works... returns 258.
myButton.onPress = function(){
trace(myNumber); // this returns "undefined".
}}
Like... why?!
Accessing Variables From One Class In Another - Not Working...
Class A instantiates classes B and C. All these classes are different. Both instances of B and C know who there parent is, so can therefore access each others varaibles through the first class.
Class B has the following variable:
Code:
private var aItemArray_array:Array;
This array is populated later on in the class.
I want to access the aItemArray_array from within class C.
I tried the following:
Code:
trace(_root.instanceOf_A.instanceOf_B.aItemArray_array)
It returns as undefined.
I tried to make the variable public, that resulted in the same trace. I also set the function in class B which sets the variable to public. That didn't work either...
What am I doing wrong here?
Accessing Stage Variables From Class
hi ..
I have written some action script (well most of the script) on main time line without using any CLASS - (bad practice) .. there are many variables that i have created there and the stage objects .. I am using those objects on main time line as ..
ActionScript Code:
this.mVideo.someProperty ...
now i have written a class say .. "Test.as" which i have placed in the same directory. now while being in that class method, how can i access variables define on the timeline actionscript + on the stage ..
how can i access that "mVideo" object from that class ??
Accessing Variables From A Root Class
I am working with the basics on getting accustomed to AS3 and working in classes. Normally, I use a lot of functions called up from the root. The class structure is appealing, but I am having a tough time with some of the things that I normally do. -One of which is to have a _root or _global variable to hold preferences (such as an audio toggle or volume). For storing session preferences that extend throughout the scope of a Flash site/app, these are preferred. Well...as you are aware, the _root and _global variables are no more. I have done a lot of research into this and I think I am close to a solution, but perhaps my syntax is off.
source: http://www.exade.com/temp/testGlobal.zip
On the root timeline, I call the class (works) and then trace it out (also works). According to this script, which is modified from http://www.kirupa.com/forum/showthread.php?p=2110830, I can use this to create a pseudo glo.bal variable. However, when I run the SAME trace function (that works on the main timeline) from within a movie clip -it fails. "Access of undefined property glo"
NOW, if I import the class into the movie clip and run the trace from that movie clip, -it works. However, this doesn't help because I am trying to store a variable that works across the entire scope of a file; not intiate a new instance of this variable for every timeline in the scope of a site. I want to initiate it once and change it from any timeline or script -globally.
Perhaps I am going about this all wrong. Therefore, if it can be pulled off a different way, the end is still the same. -I need a toggle switch(es) that can hold settings across ALL timelines and movie clips in a Flash file.
Thanks in advance!
Attach Code
package com.virion.as3.common{
public class glo {
public static var bal:Object = new Object();
if (glo.bal.testVar == undefined) {
glo.bal.testVar = true;
}
}
}
Accessing Variables Defined In Document Class
I am having trouble assessing values established in my document class.
My document class: ZoneViewer.as:
public class ZoneViewer extends Sprite {
private var zone_area_alpha_low:Number=.2;
}
This code exists on a frame within a movieclip on my main timeline:
this.zone_shape.alpha = zone_area_alpha_low;
How do I access the .2 value which is declared in my document class:ZoneViewer.as? "zone_area_alpha_low" is not working.
Issues Accessing Variables In MovieClip From A Class
I'm writing a little application to run a course, and the engine creates the navigation menu putting labels in the button etc...
So, as far as I change things like a dynamic text that's on the stage with something like
mybutton.itemText.text = my_xml.childNodes[0].childNodes[index-1].attributes["Label"];
this works, but what If I want to change a variable declared in the button?
I would like to retrieve from an XML the movie I want to load pressing this particular button, but seems like the scope of the "designed" objects and the programmed object is a little different, since with
in the button movieclip
************************
var myMovieDelegate:String = new String();
var selectedButton:Boolean = new Boolean();
-------------------------------------------
in the engine Class
mybutton.myMovieDelegate(my_xml.childNodes[0].childNodes[index-1].attributes["MovieToLoad"]);
------------------------------------------
this doesn't works, as doesn't works creating a function in the button to set the variable like
function setMovieDelegate(movie:String):Void {
myMovieDelegate = movie;
}
Where's the problem? I've included a simplified version of the interface, the classes and the code is not 100% functional...
Accessing Class Functions/variables In OnLoadInit?
Ok, I'll sum up my prob
Quote:
class fial
{
public var num = 5;
public function returnStuff()
{
return 3;
}
public function doStuff()
{
... [mclistener crap]
mclistener.onLoadInit = function()
{
trace(returnStuff() + " " + this.num);
}
}
}
The result when onLoadInit traces, "(undefined undefined)", outside the onLoadInit, it would work fine. I've tried changing this.num to num, but it was no use.
What should I do?
Thanks.
Arun
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:
ActionScript Code:
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.events.AsyncErrorEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
public class VideoObject extends Sprite {
public var videoURL:String;
public var videoWidth:int;
public var videoHeight:int;
public var ns:NetStream;
public var video:Video;
private var nc:NetConnection;
private var myEvent:Event;
public function VideoObject(videoURL:String,videoWidth:int,videoHeight:int)
{
this.videoURL = videoURL;
this.videoWidth = videoWidth;
this.videoHeight = videoHeight;
init();
}
//
//initialize
private function init():void
{
myEvent = new Event("video_loaded");
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
nc.connect(null);
}
//
//check network connection and proceed if successfull
private function netStatusHandler(event:NetStatusEvent):void
{
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetStream.Play.StreamNotFound":
trace("Unable to locate video: " + videoURL);
break;
}
}
//
//begin video streaming
private function connectStream():void
{
var ns:NetStream = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
var video:Video = new Video();
video.attachNetStream(ns);
ns.play(videoURL);
ns.pause();
video.width = videoWidth;
video.height = videoHeight;
video.x = -videoWidth/2;
video.y = -videoHeight/2;
addChild(video);
dispatchEvent(myEvent);
}
//
//handle security errors
private function securityErrorHandler(event:SecurityErrorEvent):void
{
trace("securityErrorHandler: " + event);
}
//
//handle async error
private function asyncErrorHandler(event:AsyncErrorEvent):void
{
// ignore AsyncErrorEvent events.
}
}
}
and this is the fla where I create a VideoObject instance and listen for my event:
ActionScript Code:
var myVideo:VideoObject = new VideoObject("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);
function onVideoLoaded(event)
{
trace("video loaded");
}
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 {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.NetStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.events.AsyncErrorEvent;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
public class VideoObject extends Sprite {
public var videoURL:String;
public var videoWidth:int;
public var videoHeight:int;
public var ns:NetStream;
public var video:Video;
private var nc:NetConnection;
private var myEvent:Event;
public function VideoObject(videoURL:String,videoWidth:int,videoHeight:int)
{
this.videoURL = videoURL;
this.videoWidth = videoWidth;
this.videoHeight = videoHeight;
init();
}
//
//initialize
private function init():void
{
myEvent = new Event("video_loaded");
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
nc.connect(null);
}
//
//check network connection and proceed if successfull
private function netStatusHandler(event:NetStatusEvent):void
{
switch (event.info.code) {
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetStream.Play.StreamNotFound":
trace("Unable to locate video: " + videoURL);
break;
}
}
//
//begin video streaming
private function connectStream():void
{
var ns:NetStream = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
var video:Video = new Video();
video.attachNetStream(ns);
ns.play(videoURL);
ns.pause();
video.width = videoWidth;
video.height = videoHeight;
video.x = -videoWidth/2;
video.y = -videoHeight/2;
addChild(video);
dispatchEvent(myEvent);
}
//
//handle security errors
private function securityErrorHandler(event:SecurityErrorEvent):void
{
trace("securityErrorHandler: " + event);
}
//
//handle async error
private function asyncErrorHandler(event:AsyncErrorEvent):void
{
// ignore AsyncErrorEvent events.
}
}
}
and here is the .fla where I create a videoObject and listen for my event:
PHP Code:
var myVideo:VideoObject = new VideoObject("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);
function onVideoLoaded(event)
{
trace("video loaded");
}
Accessing Root Variable From A Class File.
I have a Movie clip class named MY_MC,
and would like to access to root level variable.
fla timeline
Code:
var Status:String = "ok";
MY_MC.as
Code:
package{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class MY_MC extends MovieClip {
public function MY_MC() {
trace(Status); // here I am trying to access.
this.addEventListener(MouseEvent.MOUSE_OVER,lampOn);
}
private function lampOn(e:MouseEvent):void
{
trace("OVER");
}
}
}
How Can I do this?
Thank you.
Accessing Variables From A Php File
hey, i want to access variable from a php file (basically, it'd be just showing variables i need depending on the browser version...) how can i use those accessed variables in my flash movie?
so far, i can only get those variables to show up in a text field... i'm not sure what the problem is...
Accessing Variables From A .txt File
I am able to to get variables from a txt file to show in a text field, but I also want to have buttons trigger get url actions using values from variables in the text file.
I don't know what limits there are if any, but can you use the following sets of code or should there be something else?
To get the text file, I use:
loadVariablesNum("settings.txt", 0);
This works fine for text fields, but when I try to trigger get url actions, I use the following which doesn't work:
on (release) {
getURL(aextension);
}
What I am trying to do with the getURL is actually have it combine 2 parts. If the person clicks a1 for example, then I want it to get "a1.mp3" or "a1.wav" depending on if aextension = .wav or .mp3 in the text file. Right now I am testing to see if it just tries to launch one of them, but instead it spits out "undefined".
If I put:
on (release) {
aextension = "testing";
getURL(aextension);
}
This tries to get an address "testing", so I see I am not properly accessing the text file in the previous script. What should I do?
Accessing Data From A .txt File Via Dynamic Variables
basically i want to assign a dynamic variable to the path of data in a specific txt file, which can then be loaded.
I dont have a prob with the loading of the .txt file itself, but converting my dynamic variable (which acts as the path to access the data within the .txt file) into something useable
for instance, i need to combine the path below 'loadVarsText.pic' with a specific number from the variable 'imgCnt'.
id="loadVarsText.pic"+_root.imgCnt
so if 'imgCnt' = 1, then the variable 'id' = 'loadVarsText.pic1'. that all works cool, but how can i use my variable 'id' to load the specified data from my .txt file? (i dont have problems loading data from txt file per se, just loading it via the dynamic variable rather than a preset path)
any help on this would be greatly appreciated, thanks
Accessing Variables From An Externally-Defined XML File
Hi All-
So, I'm starting to jump onto the AS3 bandwagon, and have been studying this for a couple of weeks now... and what a ride it's been already!
As an exercise, I'm trying to put together an XML parser. Everything works perfectly for my needs if I use:
ActionScript Code:
xmlLoader.load(new URLRequest("someXML.xml"));
However, if I define "xmlURL", below, with SWFObject's addVariable, I have no idea how to access the XML data on the "global" timeline:
ActionScript Code:
xmlLoader.load(new URLRequest(xmlURL));
In AS2, accessing this would have been easy, since it would then become a root variable, but now that AS3 has no globals, I'm at a loss. From what I gather, I'm supposed to use loaderInfo? I've found several tutorials but they all seem to come up with "undefined blah blah blah". Please help, this is killing me!
Aside form this, I'm liking AS3!
Accessing User Defined Variables In A Text File...
I have a text file (let's call it "test.txt") which has a string of variables and their corresponding values. In my flash application, I have a TextInput component for a user to type their name, and a ComboBox component for the user to choose a value.
I want to be able to use the name the user typed in to jump to the variable in the test.txt file and modify its corresponding value.
I figured something like this would work:
code:
var result_lv:LoadVars = new LoadVars();
var login_lv:LoadVars = new LoadVars();
login_lv.username_ti.text = combobox.value;
login_lv.sendAndLoad("test.txt", result_lv, "POST");
However, the big problem is, it doesn't seem to like "login_lv.username_ti.text" -- using 'trace', it's always showing up as undefined.
Basically, if the user types 'Bob' as his name, I want to modify login_lv.Bob, but I don't want to have to do this with a whole bunch of 'IF' statements. Is there something I'm missing, or is there a better way to do this altogether?
Thanks!
-Tom
Scope In Object Class File Using LoadVars - Help
Hi guys,
please help, i'm pulling my hair out!! i can't seem to get my head around scopes within a class file i've tried to create..
the aim of the class file is to go and retrieve a news article form a mysql database and store data such as "headline" and "textBody" etc in it so that i can then display it in a dynamic text box later in the movie file.
here is the code on the flash file creating the flash:
Code:
import as.*
trace("step 1");
var testING:newsArticle = new newsArticle(3);
trace ("step 2");
trace ("head = "+testING.headLine + " &id = "+testING.aID);
here is the actual class file newsArticle.as...
Code:
import mx.utils.Delegate;
class as.newsArticle {
var aID:Number;
var table:String = "sales_headlines";
var returnPage;
var graphic:String = "";
var headLine:String;
var bodyText:String = "";
var mainText:String = "";
var catID:Number = 0;
var displayAsNews:Number = 0;
var articleDate;
var $loader:LoadVars;
var $url:String = "http://www.xyz.com/flash/getdata.php";
var thisObj;
function newsArticle($id) {
//----------------------------------------------
// article is being created so go to the
// database and get all the details
//----------------------------------------------
aID = $id;
var thisObj:newsArticle;
_global.thisObj = this;
init();
execute();
trace ("sweet "+headLine);
} // end of constructor
function init () : Void {
$loader = new LoadVars();
$loader.onLoad = Delegate.create (this, onLoad2);
}
function execute () : Void {
$loader.load($url);
}
function onLoad2 (success:Boolean) : Void {
if(success) {
_global.thisObj.headLine = $loader.headline0;
trace ("ok ----- "+headLine);
} else {
trace ("bad !");
}
}
} // end of class file
and finally here is the trace output..
Code:
step 1
sweet undefined
step 2
head = undefined &id = 3
ok ----- The world's first 100Mbps Hotel Internet Pipe
Please can anyone advice on what the heck i'm doing wrong??? I want to be able to call "testING.headLine" anywhere in my movie file.. how do i make it a global object? and how do i populate the class variables so they can be accessed from the .fla file.... the aID works but not the headLine arrghhh!
Thanks in advance for any advice...
How Can I Pass A Parameter From A Class To An Object Created In The .fla File?
Hi,
I am new here in this forum.
I have this class, which is working fine, but I would like to pass a parameter to the objects in my .fla file and I have no idea how.
This is a class that can be apply to any object to fade it, the problem is that the alpha percentage is fixed, and I would like to have different percentage on each object.
How could I accomplish this task?
ActionScript Code:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import gs.TweenLite;
import fl.motion.easing.*;
public class TestClass {
private var _clip:MovieClip;
public function TestClass(clip:MovieClip) {
_clip = clip;
_clip.addEventListener(MouseEvent.MOUSE_OVER, fadeIn);
_clip.addEventListener(MouseEvent.MOUSE_OUT, fadeOut);
}
function fadeIn(event:MouseEvent) {
TweenLite.to(_clip,1,{alpha:.5});
}
function fadeOut(event:MouseEvent) {
TweenLite.to(_clip,1,{alpha:1});
}
}
}
// This is the code I’m using in my fla file (objects in my fla file)
ActionScript Code:
var testing:TestClass= new TestClass(myMc);
var testing2:TestClass= new TestClass(myMc2);
var testing3:TestClass= new TestClass(myMc3);
Thank you to all in advance,
fs_tigre
How Do I Link An Object On The Stage To An External Class File?
I have a dynamic textfield called neighName on my Flash stage. I also have a movieclip that I call a region on my stage. When I mouseover the region, I want a word to display in a little popup *and* I want some text to display in my textfield. I have an external .as file for handling the region. I can make the code "see" my region, but I can't seem to make it see my textfield, although no errors are being thrown. Help, anyone?
Attach Code
(From the .fla:)
var neigh_arr:Array = new Array(90);
...
neigh_arr[0] = new Region(neighborhoods.Morningside, neighName);
(From the external .as file:)
package {
import flash.events.*;
import flash.geom.ColorTransform;
import flash.geom.Transform;
import flash.display.MovieClip;
import flash.filters.GlowFilter;
import flash.filters.BitmapFilterQuality;
import flash.xml.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.text.*;
import flash.display.Loader;
import flash.net.URLRequest;
public class Region extends MovieClip {
private var neigh:MovieClip;
private var mySprite:Sprite = new Sprite();//popup
private var neighOver:TextField = new TextField();
var neighOverTF:TextFormat = new TextFormat();
private var neighName:TextField;
//Public functions
public function Region(neigh, neighName) {
initiate(neigh, neighName);
}
public function initiate(neigh, neighName) {
this.neigh = neigh this.neighName = neighName;
neigh.addEventListener( MouseEvent.ROLL_OVER, handleRollover);
neigh.removeEventListener(Event.COMPLETE, handleRollover);
neigh.addEventListener( MouseEvent.ROLL_OUT, handleRollout );
neigh.removeEventListener(Event.COMPLETE, handleRollout);
}
private function DrawRectangle(xPos:Number,yPos:Number,rWidth:Number,rHeight:Number,color:uint, myAlpha:Number):Sprite {
var s:Sprite = new Sprite();
s.graphics.lineStyle(2, 0xcccccc);
s.graphics.beginFill(color, myAlpha);
s.graphics.drawRect(xPos,yPos,rWidth,rHeight);
s.graphics.endFill();
return s;
}
private function makeTextField(tf:TextField, myText:String, myX:int, myY:int, myTF:TextFormat) {
//var tf:TextField = new TextField();
tf.width = 250;
tf.text = myText;
tf.setTextFormat(myTF);
mySprite.addChild(tf);
tf.x = myX;
tf.y = myY;
}
public function handleRollover(pEvent:MouseEvent):void {
//get the name of this region
var st:String;
st = pEvent.target.name;
st = st.replace("_", " ");
var popupWidth:Number;
popupWidth = st.length * 8;
//make a popup with the region name in it
mySprite = DrawRectangle(0,0,popupWidth,20,0xf2f2f2, .95);
mySprite.x = pEvent.stageX - popupWidth ;
mySprite.y = pEvent.stageY + 10;
neigh.stage.addChild(mySprite);
neighOverTF.font = "Verdana";
neighOverTF.size = 12;
neighOverTF.color = 0x666666;
makeTextField(neighOver, " " + st, 0, 0, neighOverTF);
neighName.text = st; //nothing happens
}
How Can I Pass A Parameter From A Class To An Object Created In The .fla File?
Hi,
I have this class, which is working fine, but I would like to pass a parameter to the objects in my .fla file and I have no idea how.
This is a class that can be apply to any object to fade it, the problem is that the alpha percentage is fixed, and I would like to have different percentage on each object.
How could I accomplish this task?
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
import gs.TweenLite;
import fl.motion.easing.*;
public class TestClass {
private var _clip:MovieClip;
public function TestClass(clip:MovieClip) {
_clip = clip;
_clip.addEventListener(MouseEvent.MOUSE_OVER, fadeIn);
_clip.addEventListener(MouseEvent.MOUSE_OUT, fadeOut);
}
function fadeIn(event:MouseEvent) {
TweenLite.to(_clip,1,{alpha:.5});
}
function fadeOut(event:MouseEvent) {
TweenLite.to(_clip,1,{alpha:1});
}
}
}
// This is the code I’m using in my fla file (objects in my fla file)
var testing:TestClass= new TestClass(myMc);
var testing2:TestClass= new TestClass(myMc2);
var testing3:TestClass= new TestClass(myMc3);
Thank you to all in advance,
fs_tigre
Loading Variables In A Class File
as my postcounts reveals im kinda uhm..new here , so for starters: hi ppl of the US-forum, good to be here and hopefully we'll be helping eachother out in the time to come
now my problem,im kinda stuck on this for quite a while and cant really find a way to solve it on google and too many blogs so i hope you guys can help (also im not sure if this has to be in the AS forum or OOP, sry if i put it in the wrong one )
so, i have a class World. this uses has a variable map:Array. this map variable's data is declared in an external txt file. i think you already see the big picture here, loading different map for different level, exactly, a tilebased game engine
in the "old" as1 way i use the #include directive, but this is forbiddin in class files. how the heck am i gonna load this thing inside my class file??? i considered loadvars but couldnt get it working since ive been slacking on my AS2.0 (which ive been using for only a year so bare with me )
sry if i talked to much, i hear that a lot
cheers, Reinier
I Need Save Object Variables To File
I need save object variables to file, how can i do that? For example: I have object- rectangle with variables x,y positions and width,height of this rectangle. I need save this variables to txt file or send to same file (maybe PHP)..
Guncha-z
[F8] Unable To Access Variables In A Class File
Hi,
I am unable to access variables written in a class file.
This is the class file:
class readXML {
public var modArray:Array;public function setModule() {
modArray=new Array("mod1","mod2","mod3","mod4");
}
public function getModule() {
trace('Mod Array: '+modArray);
}
public function readXML() {
}}
When I access the getModule method from flash (on click of a button), I get modArray as undefined.
Any clues how I could get the data of modArray?
Regards,
Abhi
Unable To Access Variables In A Class File
Hi,
I am unable to access variables written in a class file.
This is the class file:
class readXML {
public var modArray:Array;
public function setModule() {
modArray=new Array("mod1","mod2","mod3","mod4");
}
public function getModule() {
trace('Mod Array: '+modArray);
}
public function readXML() {
}
}
When I access the getModule method from flash (on click of a button), I get modArray as undefined.
Any clues how I could get the data of modArray?
Regards,
Abhi
Access To Variables Inside Class File
Hello,
I'm trying to set up a class file that will read a bunch of links from an XML document so I can populate some buttons on the stage. The problem I am having is gaining access to the links within the class file. I have no clue how to get at "theWebsite" from the main document. Any help would be greatly appreciated!
This is what I have so far
Class file:
Code:
package {
import flash.display.MovieClip;
import flash.display.*;
import flash.text.*;
import flash.net.*;
import flash.events.*;
public class xmlLinkLoader{
//VARIABLES & Event Listeners HERE
trace("xml Link Loader CLASS Imported");
public var theText:TextField;
public var theWebsite:String;
public var myWebsiteLink:String;
public var myURLLoader:URLLoader= new URLLoader();
public var xmlData:XML = new XML();
public var myURLRequest:URLRequest= new URLRequest("links.xml");
public function xmlLinkLoader() {
myURLLoader.load(myURLRequest);
myURLLoader.addEventListener(Event.COMPLETE,dataOK);
}
public function dataOK(myevent:Event):void {
trace("xml loaded");
xmlData = new XML(myevent.target.data);
for (var i=0; i<xmlData.splashlink.length(); i++) {
var websiteLink = xmlData.splashlink.@theBandsWebsite;
}
populateMe();
trace(websiteLink);
}
public function populateMe() {
trace ("populated");
var theWebsite = xmlData.splashlink.@theBandsWebsite;
}
//
}
}
Document:
Code:
import xmlLinkLoader;
var myxmlLinkLoader= new xmlLinkLoader;
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";
}
}
}
}
Loading Variables From Txt File, Scale Object According To Value?
I'm relativly new to actionscript, but I'm getting along well enough with it.
The problem I have right now is that I'm trying to make a dynamic shockwave file which loads updates for the site out of a text file. I've managed well enough with the text strings for the updates, but the biggest problem is tring to make an object scale according to a value set in the text file.
What I'm doing is this: Loading the text file with the loadvariables command, (which has worked for the text update part) and also loading a variable for a progress bar(with the same text file), which is supposed to show how far along I am in a project. But when I tell the object to scale according to the value loaded by the text file, nothing happens. I thought this might be because of the value being a string instead of a numeric value, but even when I use the NUMBER funciont to transform a string into a numeric value, it still doesn't work. If somebody could tell me what I'm doing wrong with my script, or post an example, I'd be very grateful.
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!
Output Variables From LoadVars Object To Text File.
from what i've read so far. it seems this isn't possible without PHP script or something similiar. i have no knowledge of those scripts. only xhtml and java. what i have is a LoadVars object that loads like 30 variables from a text file. i then need to write all the variables in the LoadVars object back to the text file after i add to them.
thanx guys
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);
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?
Accessing A Property Of An Object Within An Object
I have modified a simple button object, which I called the OP Button in the library, and it contains two dynamic text fields. I had to add these text fields because I encountered a problem. Having the text above the button caused the button not to activate when the user went over the dynamic text field. Tried to have the text below the button, but the blue highlight with the button made the text fuzzy. I need to have the text dynamic because I need it to hold different values.
I have created the new button. In the library of Flash it is registered as OP Button ( a name I gave the button type ). I can edit the button and see the dynamic text object, which I gave the name of NormalText. I need to know how to change the .text property of the dynamic text located in the modified simple button.
The instance of the newly created button is OP4Button and the name of the dynamic text field within this button is called NormalText. How do I change the .text property from the main stage action script?
The button was created in design mode and not through action scripts. Even though I created in design mode, I need to access it through Action Script. Any help will be greatly appreciated.
Thank you
Edited: 06/16/2007 at 10:49:18 AM by David Cowdery
Accessing Object Name
Is there a way to access the name of an object? Specifically, I need to have access to the name of a TextFormat object. Here is simple version of what I would like to accomplish:
var Foo = "The name of this object is: " + TextFieldInstance.getTextFormat(x)
However, this returns "The name of this object is: [object Object]"
Any suggestions?
Thanks in advance!
-Aaron
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 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
|