Initializing A Class/Component - Am I Doing This Right?
I'm trying to build a standard Pop Up confirmation window that I can use throughout my application. I created a MovieClip Symbol in the library called PopUpBox, and then I put this actionscript on it's first frame so I can use it as a class and call methods on it like 'setLabel()'.
Right now I'm just setting a default label in the init function, but that's not showing up in the window. I'm also trying to call the setLabel method from my main movie, but that's not working either. Can somebody have a look-see and tell me what I might be doing wrong?
Code: #initclip
function PopUpClass(){ this.init(); }
Object.registerClass("PopUpBox",PopUpClass); PopUpClass.prototype=newMovieClip(); PopUpClass.prototype.init=function(){ this.txtLabel.text = 'wuz up mang'; }
PopUpClass.prototype.setLabel = function(lbl){ this.txtLabel.text = lbl; }
PopUpClass.prototype.getLabel = function(){ return this.txtLabel.text; }
#endinitclip stop();
Thanks, Adam.
FlashKit > Flash Help > Flash MX
Posted on: 09-08-2002, 12:03 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Initializing A Class To Broadcast
I have a class that i'm using, and want to be able to do something similar to the following:
ActionScript Code:
var myObj = new ClassObject(arg1,arg2);
myObj.onEvent = function(param) {
trace(param);
}
I realize that this has been talked about time and time again but every topic i've found with this varies slightly and doesnt work for me. I import the asbroadcaster class, and the first bit of the class looks something like this:
ActionScript Code:
import AsBroadcaster;
class ClassObject {
function ClassObject(param1:String, param2:Number) {
AsBroadcaster.initialize(this);
this.addListener(this);
this.broadcastMessage("onEvent");
}
}
it really doesnt seem right to me to have the class object add itself as its own listener, but that's the only way i can think of doing it. any help?
thanks,
chris
Problem Initializing Authored Controls In Document Class.
What is the proper method to initialize authored controls in actionscript document class? I tried to disable a button and initialize a text input in the document class constructor but it does not take. Here is a code excerpt...
//Document class for my *.FLA document.
public class Recorder extends MovieClip {
public function Recorder() {
myPb.addEventListener(...
myPb.enabled = false; //This does not work!!!
myTextInput.text ="Some text"; //This does not work!!!!
stop();
}
}
The ctor does get called and the buttons event handler does get initialized. However, the button is NOT disabled and the text inputs text is the same as was input into the authoring tool using the component inspector.
Should such code be placed somewhere other than the constructor?
Creating A Component Within A Component Class
Basically I have a component with I have associated a class with - and then attached it to stage using attachMovie and make references to it using its linked name which works great. However within this class I want to attach another movie clip component - which works however how to I reference this second component from this class using linkage doesnt work neither does assigning it to variable. The only way is to call the class - which gives undesired results.
What is the proper way to have a component within a component?
Initializing MC's
Hi All,
I have a problem.
I have 20 instances of my MC on 20 different layers.
At some point I need to initialize the _x position of all of them back to 0.
How can I do this?
Re-initializing Movieclip
Can i re-initialize a movieclip from another ? If yes, what is the comand line ?
Thx, hacook
[Edited by hacook on 06-26-2002 at 05:59 AM]
Initializing Variables
dear all, could someone please tell me what is wrong with the following actionscript.
all i want is that the default language is german and all the dynamic text boxes contain german text - unless the viewer changes the language via a button, and then all the dynamic text boxes change to english.
// initialize the website language
language = german;
// set the text inside the dynamic text box
if (language==german) {
_root.tips.dynamictextbox1 = "EINGANG";
}
else {
_root.tips.dynamictextbox1 = "ENTER";
}
Initializing Text
Having a small problem with text.. My form worked before using variables, but i'm trying to learn to use the text property by giving an input box an instance name..
The boxes are empty at the start, but after the form is submitted, i run a function clearForm(), but it doesnt clear...
anyway, here's an FLA
thanks in advance.
-myk
Help W/ Initializing A Variable
I have one scene that I want to use a variable (I think) to determine if a certain amount of questions have been answered correctly, to go to and stop on the last frame. I have actionscript in the first frame, and in a few other key frames along the way. Its not working, and I'm hoping someone can help me out and tell me what I'm doing wrong. Here's what I've got so far:
Attach Code
//frame 1 actionscript:
stop();
init();
correctLocks=0
sally_btn.onRelease=function(){
gotoAndStop(5);
}
mary_btn.onRelease=function(){
gotoAndStop(10);
}
sam_btn.onRelease=function(){
gotoAndStop(15);
}
jane_btn.onRelease=function(){
gotoAndStop(20);
}
tim_btn.onRelease=function(){
gotoAndStop(25);
}
//frame 5 actionscript (same on all except the names are different)
stop();
sallyright_btn.onRelease=function(){
gotoAndStop(1);
sally_btn._visible=0;
sallyimage_mc._visible=0;
sallybckgrd_mc._visible=0;
sallylock_mc._alpha=100;
correctLocks++;
if(correctLocks==5){
gotoAndStop(30);
} }
Initializing Code - Where?
Hi.
I have 60 small Movieclips, and all have the same code. Until now, I enter in each MovieClip, and type at it's main timeline: include "myCode.as", where the file myCode.as contains the code as I would have written it in the normal main-timeline of each Movieclip.
The problem is that It's too exhausting to enter in each movieclip and type that code.
Thus, is there any way to add at the main-timeline of each movieclip a code, from it's parent's MovieClip?.. I.e.
for (i=0; i < 60; i++) {
MovieClip(getChildAt(i)).InitMainTimeLineCode() = function { include "myCode.as"; }
}
..and this code to me added in the main-timeline of the clip?
Or any way, to force via code, MovieClips to get their source code, from .as files during run-time?.... :/....
Array Re-initializing
I have some code that initializes an array
(arrQAnswer) that stores what button the user clicked on (0,1,2, or 3). That option it put into arrQAnswer, then compared against arrCorrectAnswer to see if the user got the question right.
The problem is that for each time the user clicks on a button, they are taken to a new screen to display feedback based on the answer of the question. If the user gets the question wrong they are returned to the original screen and try again.
This is where arrQAnswer is screwing up (or more likely, where I am screwing up).
On the first question where the user chooses an answer, then returns to that screen, arrQAnswer re-intializes. Is there a way to stop this from happening? Note that it only happens on the first question, I think that is because the first question is on the same frame as the code (below):
ActionScript Code:
arrQAnswer = [];strCorrectAnswers = "3,3,0";arrCorrectAnswer = strCorrectAnswers.split(",");currentQuestion = 0;numQuestions = arrCorrectAnswer.length;feedbackNav;numScoreTotal = 0;////---------ANSWER FUNCTION-------------//answer = function (choice) { blnChoiceFirst = (arrQAnswer[currentQuestion] == null || arrQAnswer[currentQuestion] == undefined); trace("blnChoiceFirst"+currentQuestion+" "+blnChoiceFirst); //arrQAnswer.push(choice); arrQAnswer[currentQuestion] = choice; strFeedback = arrFdBk[currentQuestion][arrQAnswer[currentQuestion]]; if (arrQAnswer[currentQuestion] == arrCorrectAnswer[currentQuestion]) { feedbackNav = 1; currentQuestion++; numScoreTotal += Number(blnChoiceFirst); } else { feedbackNav = 0; } gotoAndStop("feedback");};
here is the file, if you want to check it out
Initializing A MovieClip
this is my code
stop()
container.loadMovie(_root.movie)
this.onEnterFrame=function(){
bar._xscale=Math.round(container.getBytesLoaded()/container.getBytesTotal()*1070)
spraycan._x=Math.round(container.getBytesLoaded()/container.getBytesTotal()*75)
if(container.getBytesLoaded()==container.getBytesT otal()){
delete this.onEnterFrame;
gotoAndPlay("done")
}
}
can some one help me should i initialize these clips first then the code or can i put the code and the preloader in the same frame
the reason why i'm posting is because my site works well on ie not on anyother browser its crazy thanks in advanced
Help On Initializing Variables
Hi Everyone,
I need to initialize variables to a movieclip. so i am doing this with putting this script on the movieclip
{
i = 50;
}
but it giving me error "Statement must appear within on/onClipEvent handler{ "
I have seen this code working on some other examples. i know that if i put
onClipEvent (load) {
i=50;
}
then it works fine. but why the first code creating problem.
PlZ help
Array Re-initializing
I have some code that initializes an array
(arrQAnswer) that stores what button the user clicked on (0,1,2, or 3). That option it put into arrQAnswer, then compared against arrCorrectAnswer to see if the user got the question right.
The problem is that for each time the user clicks on a button, they are taken to a new screen to display feedback based on the answer of the question. If the user gets the question wrong they are returned to the original screen and try again.
This is where arrQAnswer is screwing up (or more likely, where I am screwing up).
On the first question where the user chooses an answer, then returns to that screen, arrQAnswer re-intializes. Is there a way to stop this from happening? Note that it only happens on the first question, I think that is because the first question is on the same frame as the code (below):
ActionScript Code:
arrQAnswer = [];strCorrectAnswers = "3,3,0";arrCorrectAnswer = strCorrectAnswers.split(",");currentQuestion = 0;numQuestions = arrCorrectAnswer.length;feedbackNav;numScoreTotal = 0;////---------ANSWER FUNCTION-------------//answer = function (choice) { blnChoiceFirst = (arrQAnswer[currentQuestion] == null || arrQAnswer[currentQuestion] == undefined); trace("blnChoiceFirst"+currentQuestion+" "+blnChoiceFirst); //arrQAnswer.push(choice); arrQAnswer[currentQuestion] = choice; strFeedback = arrFdBk[currentQuestion][arrQAnswer[currentQuestion]]; if (arrQAnswer[currentQuestion] == arrCorrectAnswer[currentQuestion]) { feedbackNav = 1; currentQuestion++; numScoreTotal += Number(blnChoiceFirst); } else { feedbackNav = 0; } gotoAndStop("feedback");};
here is the file, if you want to check it out
Initializing A MovieClip
this is my code
stop()
container.loadMovie(_root.movie)
this.onEnterFrame=function(){
bar._xscale=Math.round(container.getBytesLoaded()/container.getBytesTotal()*1070)
spraycan._x=Math.round(container.getBytesLoaded()/container.getBytesTotal()*75)
if(container.getBytesLoaded()==container.getBytesT otal()){
delete this.onEnterFrame;
gotoAndPlay("done")
}
}
can some one help me should i initialize these clips first then the code or can i put the code and the preloader in the same frame
the reason why i'm posting is because my site works well on ie not on anyother browser its crazy thanks in advanced
Initializing A Movieclip
Hi Everyone,
I created a movieclip, put some functions within. But I cannot access the functions or properties on the same frame. Why is it so ? How can I get around it ?
Thanx
Rajesh
Initializing Variables
How can I initialize Flash variables from the HTML page that contains it? For example, I have two variables _root.preloadalbum and _root.preloadsong, to which I would like to assign values, by means of JavaScript.
In the first frame of the flash file, I stop playback and send an FSCommand.
My FSCommand function looks like this:
function listen_DoFSCommand(command, args) {
window.alert("Blah");
document.listen.SetVariable("_root.preloadalbum", "ddfa");
document.listen.SetVariable("_root.preloadsong", "ddfa-447e");
document.listen.Play();
}
The "Blah" pops up, the animation plays, but the variables don't get changed.
Is there something I'm doing wrong?
Thanks in advance
Will
Initializing MovieClip
is it safe to introduce a movieclip and give it code at the same time on the same frame.Or should i introduce it first then follow it with some functions on frames that follows.
Initializing Array Question ***************
I use this(*) in my script to initialize a specific type of array. 1 array with 6 arrays in it. But i want to keep that number (here 6) variable. Is it posible to initialize this in an other way? (new Array()...???)
foto_array=[[],[],[],[],[],[]] //(*)
Anyone ideas? thanks a lot
Initializing Data From A Db At Startup
I am sure this is another of those problems that has a very simple answer that I am just not seeing, so I would appreciate any help you folks can offer.
I have a mc called Main.swf that loads another .swf into a holder mc called mcSum. McSum has a button that will load data from a database and display it in the mc. There is a similar button on the Main.swf at the root level that will also load this same data into the mcSum mc. It is used strictly for testing at the moment and will be removed later. These all work fine. When either button is pressed, the data is loaded and displayed in mcSum correctly.
The problem is that I want to have the Main.swf automatically load the mcSum mc at startup and populate the data fields. The Main.swf will load the mcSum mc at startup and display it correctly. However, I cannot get the data downloaded at this point. I have removed the same code from the buttons~{!/~} ~{!.~}onRelease~{!/~} function and placed it in the root timeline along with the following code:
.
.
.
loadMovie("Summary.swf", mcSum);
gettingData = setInterval(checkLoaded, 10);
}
function checkLoaded(){
if (mcSum.getBytesLoaded()>=mcSum.getBytesTotal()){
//trace ("checkLoaded called");
// The following is code from the buton ~{!.~}onRelease~{!/~} function, which works both from the main timeline and from the mcSum mc.
mcSum.onLoad = function(){
//Send these vars to the database
mcSum.XMLDoc = new LoadVars();
mcSum.XMLDoc.Session = thisSession;
mcSum.XMLDoc.sDate = startDate;
mcSum.XMLDoc.eDate = endDAte;
mcSum.XMLDoc.AccountID = AccountID;
mcSum.XMLDoc.CompareTo = Compare;
mcSum.XMLDoc.ShowBy = ShowBy;
// Use this URL when online or testing with live data
//mcSum.XMLDoc.sendAndLoad("LdData.asp", mcSum.XMLResponse, "POST");
// Use this URL for testing. Comment out when not in test mode
//mcSum.XMLDoc.sendAndLoad("LdData.xml", mcSum.XMLResponse, "POST");
//trace ("onLoad called");
clearInterval(gettingData);
};
}
}
Individually, everything works as expected. Together they do not.
Thanks for any help.
Regards,
WTG
Initializing Movieclips On The Stage :s
Hi all, i have what seems like a very simple task, but i cant figure out how to do it!
* I create a custom button movieclip, and then put instances of this on my stage.
* In this custom movieclip I have a textfield for display (called DisplayText).
* I have a function in this movieclip called Init(S:String), which does DisplayText.text = S;
* from my _root movie (parent to the instanced buttons), i want to do main but1.Init("Home"); but2.Init("blah");but3.Init("blah2), etc. but it doesnt work.
My _root movie is only 1 frame long, and i cant figure out how to do this! If i make _root 2 frames long, and put the buttons on the stage in frame 1, and put the init commands on frame 2 it works. SO i guess its something to do with the fact that on frame one, the Init command doesnt exist yet. Is there someway of saying when but1 has been fully created, then call the Init command?
I tried doing: but1.onLoad = function() { this.init("Home");} but that too did not work!!
it seems like such a simple thing I wanna do! but i cant!!!
any ideas?
cheers,
Initializing Fonts... CRASH
I bought myself a new PC. AMD 64 x2 4200+ and 2gigs of memory blabla. I installed Flash 8 and it runned fine until I threw some 700 fonts in my windows font folder. Since I did that (or at least I think), flash crashes all the time when its starting ("initializing fonts..." > Crash). I've got the same problem with the older versions of flash, because I tried them out to test wether it was a bug in Flash 8. Photoshop starts normally and has no problems with my fonts (or at least: not anymore, with some fonts I got c++ runtime errors when selecting. I threw these fonts away and no errors occur anymore with photoshop.) Anyway...
I dont want to uninstall all of my fonts to check witch one is causing this problem, because I'm not sure which fonts are windows' fonts, and with 700+ fonts It'll cost me a lot of time.
So does anyone have a solution?
PS. Fireworks doesn't want to start too. Dreamweaver does (because it does not need to initialize fonts (as far as I know))
thx
Re-initializing Movieclip Variable
hi guys...
I am a new AS3 user. Can anyone help me on how to re-initialize my movieclip variable? I have created an actionscript that randomly display an image and will animate it. After the first image has been displayed, under certain condition, the routine repeats and will randomly select another image. My problem now is when the routine repeats, the first image still there added with the new randomly selected image.
I have this initialization:
var sp1:MovieClip = new MovieClip();
var sp2:MovieClip = new MovieClip();
I have assigned values in it by this code:
sp1.addChild(img1);
stage.addChild(sp1);
I tried using "removeChild" but was not able to make it work.
Thanks in advance for any help you can extend...
Initializing Embedded BMP With GetDefinitionByName?
Ok, so before you can create an instance of a class with getDefinitionByName, you have to declare it first, but how can I do this with an embedded asset's class if it is not created until runtime? Is this possible?
Initializing Textfield Inside An Mc
I'm trying to change the text property of a mc on frame2. The code is located at the AS layer and looks like this
_level0.butt2.texto.text="Button 2";
where butt2 is the instance name of the mc and texto the instance name of the dynamic textfield inside the mc.
I've tried with _root in place of _level0, but the trace() statement shows _level0 on the path:
trace(butt2.texto); output is:
_level0.butt2.texto
Can someone show me some light?
[MX PRO 2004 - AS 2.0] Variables Re-initializing
I am in dire straights.
The problem is that the variables are initializing every iteration of the timeline's loop - even though the movie clip does not repeat.
- I am in the process of removing AS elements to isolate the culprit -
I wanted check with the community to discover if anyone has any knowledge of this kind of incident. The .fla and .as files are too large to post, so if you would like to test the files, email me - Garrett.Christopherson@Gmail.com.
Initializing Movie Clip
I've made a movie clip with several objects in it. One of the objects I'd like to start out not visible. What is the best way to initialize a movie clip with things like that?
Flash Mx Crashs On Initializing Fonts
Hi,
I'm encountering a problem where by Flash MX crashes on start up at the 'initializing fonts' stage. It happens every time.
I've found that if I disconnect from the internet completely (I'm connecting via a network router) the problem goes away.
Can anyone shead some light on the problem? Its most annoying as I need to be constantly connected to the net whilst I work.
I'm running OS 4.4.4 on a G5 dual 2GHz Power PC.
Many thanks in advance.
Initializing Variables After LoadVars Completed
hi,
Currently, if I want to load variables from php to flash, I have to initialize each variable like
PHP Code:
var_a=this v_a
For example:
PHP Code:
var mydata:LoadVars = new LoadVars();
mydata.onLoad = function(eof:Boolean)
{
if (eof)
{
var_a=this.var_a;
var_b=this.var_b;
var_c=this.var_ac;
//etc....
}
};
mydata.sendAndLoad("data.php", mydata, "POST");
I was wondering if there is another (faster) way to initialize these variables?
Having to set 100+ variables per movie becomes tedious, having to go through each variable.
Problem Initializing LoadMovie Variables
Hello,
Im having trouble loading a clip through loadMovie and setting some properties of that newly loaded movie at the same time. For example I have an XML object loading data from a php page. The onLoad for that XML object loads a basic table movie, and tries to set the title and body fields of that movie. The problem is that I can load the movie, but I cannot set the properties of that movie until much later.
Below are the examples of the failing code. Thanks for the help, I just cant figure out how to load data into a loaded movie. Ive even tried to include the table movie in the library of the main movie, so theres no loading latency. Even preloading the movie and jut duplicating that preloaded movie. This is driving me insane!
Thanks for the help!
-thewade
//frame actionscript
this.info.onLoad=function(success) {
if (success) {
dat=this.toString().split("
",1000);
dat.pop(); //remove trailing newline
for(i=0;i<dat.length;i+=5) {
count=i/5;
filename="filter"+count;
depth=11+count;
_root.createEmptyMovieClip(filename,depth);
_root[filename].loadMovie(myURL);
//this part works
_root[filename]._x=283*Math.cos(dat[i])+322;
_root[filename]._y=283*Math.sin(dat[i])+322;
_root[filename]._rotation=dat[i]-180;
//this part doesnt
_root[filename].Topic=dat[i+1];
_root[filename].Body=dat[i+2];
_root[filename].ImgA=dat[i+3];
_root[filename].ImgB=dat[i+4];
}
}
}
//load event function for the movie Im loading:
onClipEvent(load) {
this.setTopic=function(Topic) {
TopicWindow.Topic=Topic;
}
this.setBody=function(Body) {
BodyWindow.Body=Body;
}
this.setImageA=function(ImgA) {
BodyWindow.ImageA.loadMovie(ImgA);
}
this.setImageB=function(ImgB) {
BodyWindow.ImageB.loadMovie(ImgB);
}
this.dud=function() {}
this.addProperty("Topic",this.dud,this.setTopic);
this.addProperty("Body",this.dud,this.setBody);
this.addProperty("ImgA",this.dud,this.setImageA);
this.addProperty("ImgB",this.dud,this.setImageB);
}
Problem Initializing LoadMovie Variables
Hello,
Im having trouble loading a clip through loadMovie and setting some properties of that newly loaded movie at the same time. For example I have an XML object loading data from a php page. The onLoad for that XML object loads a basic table movie, and tries to set the title and body fields of that movie. The problem is that I can load the movie, but I cannot set the properties of that movie until much later.
Below are the examples of the failing code. Thanks for the help, I just cant figure out how to load data into a loaded movie. Ive even tried to include the table movie in the library of the main movie, so theres no loading latency. Even preloading the movie and jut duplicating that preloaded movie. This is driving me insane!
Thanks for the help!
-thewade
//frame actionscript
this.info.onLoad=function(success) {
if (success) {
dat=this.toString().split("
",1000);
dat.pop(); //remove trailing newline
for(i=0;i<dat.length;i+=5) {
count=i/5;
filename="filter"+count;
depth=11+count;
_root.createEmptyMovieClip(filename,depth);
_root[filename].loadMovie(myURL);
//this part works
_root[filename]._x=283*Math.cos(dat[i])+322;
_root[filename]._y=283*Math.sin(dat[i])+322;
_root[filename]._rotation=dat[i]-180;
//this part doesnt
_root[filename].Topic=dat[i+1];
_root[filename].Body=dat[i+2];
_root[filename].ImgA=dat[i+3];
_root[filename].ImgB=dat[i+4];
}
}
}
//load event function for the movie Im loading:
onClipEvent(load) {
this.setTopic=function(Topic) {
TopicWindow.Topic=Topic;
}
this.setBody=function(Body) {
BodyWindow.Body=Body;
}
this.setImageA=function(ImgA) {
BodyWindow.ImageA.loadMovie(ImgA);
}
this.setImageB=function(ImgB) {
BodyWindow.ImageB.loadMovie(ImgB);
}
this.dud=function() {}
this.addProperty("Topic",this.dud,this.setTopic);
this.addProperty("Body",this.dud,this.setBody);
this.addProperty("ImgA",this.dud,this.setImageA);
this.addProperty("ImgB",this.dud,this.setImageB);
}
Flash Crashes When Initializing Fonts
If anyone can be of any help, I would be immensely appreciative. There are a lot of people out there with the same problem, but no answers have worked for me so far.
Issue: Approx 5 seconds after Flash MX Pro 2004 (and Flash 8 demo) splash screen hits "Initializing Fonts," Windows XP reports an error, Flash closes.
Seemingly pertinent:
• Alienware computer, XP Pro SP2 - all updates
• 1.25 GB RAM, 19.6 GB free disk space on main disk
• Macromedia Flash MX 2004 Pro (purchased full version upgraded to 7.2)
• Adobe Type Manager
• Just before Flash crashes, any open Explorer windows briefly seem to refresh, in that all the icons disappear and then reappear in an instant
What doesn't work:
• Installation
- Repair Installation
- Reinstallation
- Uninstall followed by complete wipe of all Macromedia files on the entire drive and removal of Macromedia reg values
- Doing it again but also involving registry deep-cleaning utilities.
- Brand new installation of Flash 8 demo has the same problem
• Removing Adobe Type Manager fonts
• Uninstalling Adobe Type Manager
• Repairing fonts with Font Xpress (nothing needs to be repaired)
• Deleting missfont.map file
• Deleting fonts down to the bare essentials
• Starting Flash in Safe Mode
• Starting Flash on a different user account
Other considerations:
• My hard drive has become corrupted 3 or 4 times and I have re-installed Flash many times - perhaps a hidden registration limit mechanism?
• My desktop and laptop are networked with mounted network drives and I often sync files between them.
• The Initializing Fonts thing may be the wrong path to take here, when I load Flash on my laptop, Building Workspaces directly follows Initializing Fonts. Perhaps it could be an issue with Building Workspaces.
• It could also be anything to do with the whole First Run business, since I don't think it has run since it was re-installed the last time the hdd was corrupted.
The strangest thing of all of this is that I just got a new laptop a few months ago (before the problem with Flash developed), and everything on the laptop is basically an image of the desktop. And Flash works fine on the laptop, which runs all the same processes and has almost all the same programs installed.
Please let me know if you need any more information,
Ian
Question For Array Guru's On Re-initializing Arrays
I have a flash application that constantly can call mysql to get new variables. These variables get put into arrays in Flash. However, when I call new variables, these arrays don't get reinitialized and some elements of the arrays hold the correct elements but also the old ones too. Here's what I've tried.
Right before calling the loadvariables again, I run loops on array[i] setting to "".
I've also tried array = new Array() to possibly empty them.
I have not tried any pop's though.
Does anyone know a Flash function to re-initialize or empty an array.
Thanks.
~Z~
[F8] Initializing Multiple Event Handlers With Loop
It has been a while since I've really dug into ActionScript, and boy has it changed since Flash 5!
I'm currently designing a color picker, with some 88 colors in a palette. Each one has an instance name in the format "swatch_colorname", and each should have onRollOver, onRollOut, and on Release events attached.
So this is my code so far:
code:
var colorsArray:Array = Array("Black","Snow White","White","Light Gray","Cadet","Persimmon","Nasturtium","Lemon Peel");
function swatchRollOver (overImage:String,colorName:String) {
// onRollOver code goes here
}
function swatchRollOut (overImage:String) {
// onRollOut code goes here
}
function swatchRelease (overImage:String,colorName:String){
// onRelease code goes here
}
for( var i:Number = 0; i < colorsArray.length; i++ ) {
var valueArray:Array = colorsArray.slice(i,i+1);
var displayName:String = valueArray[0];
var variableName:String = displayName.toLowerCase();
// create a valid variable name for color names with more than one word
var stringArray:Array = variableName.split(" ");
if(stringArray.length > 1) variableName = stringArray.join("");
_root.palette["swatch_"+variableName].onRollOver = function () {
swatchRollOver(variableName,displayName);
}
_root.palette["swatch_"+variableName].onRollOut = function () {
swatchRollOut (variableName);
}
_root.palette["swatch_"+variableName].onRelease = function () {
swatchRelease (variableName,displayName);
}
}
What I want to happen is for the code to go through the array colorArray, create a "variableName" based on each String in colorArray, and then pass "variableName" and "colorArray[i]" to swatchRollOver, swatchRollOut, and swatchRelease as needed.
What's happening, though, is that the event handlers are all getting the value for the last element in colorArray, ie. "Lemon Peel" and "lemonpeel" are being sent to the event handlers for "Black","Cadet", and the other colors in the array.
I'm assuming this is because "variableName" and "displayName" are being passed by reference to the event handler functions. Is there any way to pass them by value instead?
You can see some of the different things that I tried, such as reassigning the value of colorArray to a new array using Array.slice().
Initializing Vars Inside 'for' : Weird Behaviour
Hi, while trying to translate my programming knowledge to Actionscript 3 ( which is a very pleasant task ) I found out that when declaring a variable inside a for loop, that var's scope is not only the for block but the block surrounding it.
ActionScript Code:
if( something )
{
trace( i ); // i exists before its own declaration
for( var i:String in anObject )
{ }
trace( i ); // i exists outside the for block
}
Ok, that's fine with me, I can get used to it. I've tried to initialize the var used to iterate an Object with for each:
ActionScript Code:
for each( var f :fruit = null in objectWithFruits )
{ }
Flex Builder 3 doesn't raise an error there, but it doesn't initialize f to null either, so if this for each is inside another loop, f could carry old values from previous iterations.
Be careful!
PS: Yes I know, initialize the iterator before the for each, but why does the compiler permit initialization but doesn't execute it as in a regular for(...;...;...)?
Initializing Movie: Several Flash Movies, Same Folder?
Hi guys,
I'm trying to do the "initializing movie" tutorial and I'm having some trouble. When I click the button on the main page, "movie one" loads immediately (the actual "initializing movie" animation never shows up). .
I thought this was happening quickly because all the files were on my local drive (I've made "movie one" 4 mb so, I'm sure it's not because it is small). I tried uploading them to my remote server and calling the page up in my browser but now, when I click on the button, nothing happens. I've got all the files in the same folder so, I'm not sure what's going on.
Does anyone know where I may be going wrong?
Thanks very much,
artane
Class/Component Question
I am making a class that is suppose to control key board mapping. I want to use the onClipEvent(keyDown) function for and instance of this class. I can't seem to get it to work. I can use AppSimClass.porotype.onEnterFrame = function () {} but I tried this approach before and it is too sensitive to key presses. Is there any way to use an onClipEvent for a instance of a class?
How To Get Event In Component Class?
Hello,
I want to make ActionScript 2 component. I have one movie clip (my component). Inside it I have ComboBox with instance name myMovieClip. The class associated with component is
Code:
class mypackage.MyComponent extends Object{
static var symbolName:String = "parser.Deroulateur";
static var symbolOwner:Object = parser.Deroulateur;
private var myMovieClip:MovieClip;
function MyComponent(){
}
function change():Void{
trace("change");
}
}
I want to work with event change of the ComboBox. If I put it on the ComboBOx instance like this:
Code:
on(change){
trace("change");
}
it works OK but how to get it in my class? I tried with method
Code:
function change():Void{
trace("change");
}
but it just doesn't work
Please help.
Thank you
Using Tree Component In Class
Hi,
I am trying to use a tree component in flash mx 2004.
I am able to populate a tree compoenent with XML data.
On clicking of a leaf node I am updating the contents of the leaf node in a datagrid.
Alls happening fine as long as I code it in an fla document.
The moment I convert the code into a class nothing seems to happen.
Infact the constructor of the class is also not getting called. Neither can I set an breakpoints in debugg mode.
Heres the code
--------------------------------------------------------------------------
Code:
import mx.controls.Tree;
import mx.controls.DataGrid;
class treeNav extends MovieClip {
private var listArray:Array;
private var xml:XML;
private var myTree:Tree;
public function treeNav() {
var temp = this;
listArray = new Array();
xml = new XML();
xml.ignoreWhite = true;
xml.load("contact info.xml");
xml.onLoad = function() {
temp.createTree(this);
};
trace(this);
}
private function createTree(x:XML) {
myTree.dataProvider = x.firstChild.firstChild.firstChild;
trace(x);
}
public function createdata(x:XMLNode) {
var a = new Array();
for (var i in x.attributes) {
a[i] = x.attributes[i];
}
listArray[0] = a;
}
}
I have created a tree component on stage inside a movieclip and attached the above class to the movieclip.
The problem seems to be at line number 6 "private var myTree:Tree;" where I am storing a refernce to the tree compoenent on stage by the name "myTree". The moment I comment this line the constructor is called.
Not sure what is this issue,
please help.
Component And Tween Class Help
Hi All,
I have a simple component which is dynamically added to a movieClip (‘parent_mc’) and is then made a listener of that movieClip. I’m creating 5 different component instances and each one is given a unique ‘id_number’. The component uses a tween calss function for moving to a different x position. The ‘parent_mc’ broadcasts a message (this.broadcastMessage("moveComp", compId, newX); and only the component with the matching id moves to the new position.
Everything works as expected but the problem I’m having is trying to call a function to let the 'parent_mc' know when the tween has finished. Can anyone help??
Thanks,
Ty
This is a cut down of the components script.
Attach Code
#initclip
import mx.transitions.Tween;
import mx.transitions.easing.*;
//
myCom.prototype.moveComp = function(compId, newX) {
if (compId == this.id_number) {
trace("moving component "+this.id_number);
var myTweenX = new Tween(this, "_x", Regular.easeOut, this._x, newX, 0.2, true);
myTweenX.onMotionFinished = function() {
// trace works but the id_number is undefned
trace(“move finished”+this.id_number);
// calling a ‘parent_mc’ function or a function in the component doesn’t work!!
this._parent.moveFinished(this.id_number);
this.moveFinished();
};
}
};
//
myComp.prototype.moveFinished = function() {
trace (“finish moving ”+this.id_number);
};
//
Using Tween Class In A Component
hi, I have made a list menu component and it uses transitions.Back tween when open and close. Before compiling as SWC, that is as a movieclip, the component works well but after compiling as swc and import in another document, tween functions does not work. Why can I not use this classes in a component? Here is the code :
#initclip
import mx.transitions.Tween;
import com.robertpenner.easing.*;
//---------------------------------------------------------------------------------------
//constructor
function MultiListMenuClass() {
this.isOpen = false;
this.columnNumber = -1;
}
//---------------------------------------------------------------------------------------
//inherit from the MovieClip Class
MultiListMenuClass.prototype = new MovieClip();
//---------------------------------------------------------------------------------------
//methods
MultiListMenuClass.prototype.open = function() {
openTween = new Tween(this, "_y", Back.easeOut, this._y, this._height-40, 0.5, true);
this.isOpen = true;
};
MultiListMenuClass.prototype.close = function() {
closeTween = new Tween(this, "_y", Back.easeIn, this._y, 0, 0.5, true);
this.isOpen = false;
};
Attach Component Within A Class
Hello,
i'm looking for a way to add an instance to a component from a class...
Something like
Code:
class myClass extends MovieClip{
function myClass(){
}
function addComponent(){
attachMovie(thecomponent, "compoInstance", 0, 0, 1);
}
}
but i dont know about the "thecomponent" part.. i tried "textInput" but it doesn't work.. any idea?
Help With Component And Tween Class
Hi All,
I have main movieClip which creates several instances of a library component each with a different id_number variable. The components are made listeners of the main movieClip so when it broadcasts moveComp(id_number,newX) only the matching component respond and moves to the new x location.
Everything works fine but the problem I have is trying get the tween class onMotionFinished to call a function either in the parent movieClip or a function in the component itself. What am I doing wrong? Can anyone help??
Many Thanks,
Ty
This is the relevant bit of the components script.
Code:
//---------8<-----
myCom.prototype.moveComp = function(compId, newX) {
if (compId == this.id_number) {
trace("moving component "+this.id_number);
var myTweenX = new Tween(this, "_x", Regular.easeOut, this._x, newX, 0.2, true);
myTweenX.onMotionFinished = function() {
// trace works but the id_number is undefned
trace(move finished - +this.id_number);
// calling a parent_mc function or a function in the component doesnt work!!
this._parent.moveFinished(this.id_number);
this.moveFinished();
};
}
};
//
myComp.prototype.moveFinished = function() {
trace(move finished - +this.id_number);
};
//---------8<-----
Component Add In A Class And Use Object
Hi
I m creating a common class of component which i want to use in different class .
In My project i have a color.as class in which i had create a colorPicker and added it.Now i want to use it into many class where i could access all method of colorPicker without adding colorPicker Component into all class . Can it possible
Thanks
How To Get Event In Component Class?
Hello,
I want to make ActionScript 2 component. I have one movie clip (my component). Inside it I have ComboBox with instance name myMovieClip. The class associated with component is
class mypackage.MyComponent extends Object{
static var symbolName:String = "parser.Deroulateur";
static var symbolOwner:Object = parser.Deroulateur;
private var myMovieClip:MovieClip;
function MyComponent(){
}
function change():Void{
trace("change");
}
}
I want to work with event change of the ComboBox. If I put it on the ComboBOx instance like this:
on(change){
trace("change");
}
it works OK but how to get it in my class? I tried with method
function change():Void{
trace("change");
}
but it just doesn't work
Please help.
Thank you
Component Instance Name In A Class?
I am a longtime user of a very useful tool http://www.slideshowpro.net a slideshow component that has a really great API.
To use it you need to drag the component to the stage and give it an instance name in the properties pane, I'm using my_ssp. I have always coded this stuff on the first frame of the time line, such as setting the position of a TextField in relation to the component instance on the stage.
Code:
_galleryTextField.x = my_ssp.x;
_galleryTextField.y = my_ssp.y - (_galleryTextField.textHeight * 2) ;
So I had the need to create a class that will create the TextField "_galleryTextField" so I can access it as a public var in other places of my project. Here's the problem, now that I need to access the my_ssp instance name inside of this new class, It becomes an undefined property. I have imported the appropriate package, but trying to figure out how to tell this class what my_ssp is? Normally I set the Linkage in the library to make it available, like with a MovieClip, but this is a component and I can't do that in the Library. I'm thinking I need to declare it as a public var in the document class, but then I'm not sure what to set the type to? Can I make a component's instance name available to a class or am I going about this completely wrong?
I hope this makes some sense, thanks for any help.
AS 2.0 AttachMovie In Component Class Function
I am trying to attach a movie dynamically to the stage and reference its variables from a response from a php script. This method works fine in regular timeline coding, but when it is in a component class, it wont attach the movies dynamically when the component loads up. Please help.
code:
import mx.core.*;
import mx.containers.*;
import mx.controls.*;
import mx.transitions.easing.*;
//Associate custom component image
[IconFile("Menu.png")]
//declare the class and identify the parent class
dynamic class mx.controls.Menu.phpMenu extends mx.core.UIComponent{
//identify the symbol name that this class is bound to
static var symbolName:String = "phpMenu";
//identify the fully qualified package name of the symbol owner
static var symbolOwner:Object = Object(mx.controls.Menu.phpMenu);
//provide the className variable
var className:String = "phpMenu";
//Declare all movieclips and properties going to be used in component
private var mainCategoryLoader:LoadVars;
private var subCategoryLoader:LoadVars;
private var mcHolder:MovieClip;
private var backGround:MovieClip;
private var scroller:ScrollPane;
private var scrollPaneContent:MovieClip;
private var subCategory:String;
private var i:Number;
private var nexty:Number;
private var randInt:Number;
private var _rootURL:String;
private var _fileName:String;
public var statusBox:String;
public var headerBox:TextField;
//constructor
function phpMenu(){}
//Create children
private function createChildren():Void{
}
//define init method for this component, and initialize super class
public function init(Void):Void {
super.init();
randInt = int(Math.random() * 123456789);
loadMainCategories(_rootURL, _fileName, randInt);
}
//Draw
private function draw():Void{
super.draw();
this.scroller.contentPath = "scrollPaneContent";
}
//Introduce property inspector parameters
[Inspectable(defaultValue="menuLoad.php")]
public function set fileName(theFile:String){
if(theFile == ""){
trace("Please fill in a file name");
}else{
_fileName = theFile;
trace("file name is " + _fileName);
}
}
[Inspectable(defaultValue="http://")]
public function set rootURL(theRoot:String){
if(theRoot == "http://"){
trace("Please fill in a root directory.");
}else{
_rootURL = theRoot;
trace("root URL is " + _rootURL);
}
}
//declare main menu load function
public function loadMainCategories(u,f,r):Void{
mainCategoryLoader = new LoadVars();
mainCategoryLoader.handler = this;
mainCategoryLoader.sendAndLoad(u + f + "?" + r, mainCategoryLoader, "POST");
mainCategoryLoader.onLoad = function(success){
if(this.status = "ok"){
trace("loaded successfully");
trace("url is " + u + f + "?" + r);
nexty = 0;
trace("nexty is set to " + nexty);
this.headerBox.text = this.header;
for(i=0;i<this.mainCategoryCount;i++){
trace("i = " + i);
trace("header = " + this.header);
trace(this["mcHolder" + i]);
trace("nexty is set to " + nexty);
scroller.content.attachMovie("mcHolder", "mcHolder" + i, getNextHighestDepth());
//scroller.content["mcHolder"+i].subCategory.text = this["mainCategory" + i];
setProperty(scroller.content["mcHolder"+i],_y,nexty);
scroller.invalidate();
trace(scroller.content["mcHolder"+i]._height);
}
}else if(mainCategoryLoader.status = "error"){
trace("Sorry, loaded unsuccessfully");
statusBox = mainCategoryLoader.error;
}else{
trace("No response from Database");
statusBox = "Loading Menu...";
}
}
}
}
Using Component Inside Custom Class
Hi,
I'm creating a registration form that contains a ComboBox component.
This component works as expected on its own:
code:
import mx.controls.ComboBox;
for (var i = 1930; i <= 1990; i++)
{
year_cb.addItem({data:i, label:i});
}
var year_cbListener:Object = new Object();
year_cbListener.change = function(evt_obj:Object)
{
var item_obj:Object = year_cb.selectedItem;
trace(item_obj.data);
};
year_cb.addEventListener("change", year_cbListener);
But when I try to use it inside my custom class (wich will handle all the data of the registration), it simply doesn't work. The ComboBox doesn't even get populated:
code:
import mx.controls.ComboBox;
//
class Registration extends MovieClip
{
private var year_cb : ComboBox;
private var year_cbListener : Object
//
public function Registration ()
{
myInit ();
}
//
private function myInit ()
{
trace (year_cb); // works
for (var i = 1930; i <= 1990; i ++)
{
year_cb.addItem (
{
data : i, label : i
});
}
year_cbListener = new Object ();
year_cbListener.change = function (evt_obj : Object)
{
var item_obj : Object = year_cb.selectedItem;
trace (item_obj.data);
};
year_cb.addEventListener ("change", year_cbListener);
}
}
Here are the files (combobox working alone, and the class files).
Any ideas?
Thanks.
Getter/Setter Within A Class With A Component
I have a class file which loads comboboxes on the stage. In the interaction various things happen which need to be recorded, and I had done this in the past by setting properties on movie clips. I.E. -
mc1.propertyName = true/false;
I try to do that with a component and get a message saying that the property can't be created on fl.controls.ComboBox.
The property name is: isRed. It's being set like this:
combo1.isRed = true/false;
Here's the getter/setter:
public function get isRed():Boolean {
return _isRed;
}
public function set isRed(value:Boolean):void {
_isRed = value;
}
Also tried this:
[Inspectable(defaultValue=false)]
public function get isRed():Boolean {
return _isRed;
}
public function set isRed(value:Boolean):void {
_isRed = value;
}
Any ideas? Thanks.
Instantiating MXML Component Within AS3 Class
I have a MXML component that is pretty much this:
MXML Component name is "TestPlan.mxml"
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300">
</mx:Canvas>
inside my AS3 I do this
pt:TestPlan = new TestPlan()
hbox.addChild(pt);
I get a TypeError #1009.
Can anyone help?
|