Sections
You are here: Home Forum Flash problems passing info between classes

problems passing info between classes

Up to Flash

problems passing info between classes

Posted by cara thompson at August 08. 2008
I'm working with as3 and trying to pass info from one class to another. I made a class for my make control board (Make.as) and am trying to take input from the board from that class into the main class to change alpha based on light input. Make sense? I've done all kinds of tests with other (non-make board) classes as well as getting the make class to work on it's own , but for some reason, my main doc can't read the make.alfNum number. I can trace it from the make class-- it traces just fine! But when I try to bring it into the other class (using var alfa=make.alfNum) it traces as NAN. Any ideas? I'm totally stuck here as my whole project hinges around me being able to transfer this info. This is my first time using the make board. I used the example files and got it to work just fine. I'm just stuck on this one problem. Hope that's clear enough. I'm somewhat new to working with multiple classes as well. HELP GREATLY APPRECIATED!

Re: problems passing info between classes

Posted by Liam Staskawicz at August 09. 2008
I'm not sure I understand your problem - perhaps you could paste some code in a pastebin and provide the link? Somewhere like http://pastie.org ?

Re: problems passing info between classes

Posted by cara thompson at August 09. 2008
Sure. I'd appreciate your help. Here is the Make.as file: http://pastie.org/250612 I cannot get alfNum to feed into my other class. It just registers NAN but is outputting from the trace statements correctly. the main class looks (in brief) like this: ----- public function mainClass(){ var alfa:Number; alfa=make.alfNum; trace ("main file says friggin alfa is " +alfa); ------ this trace says alfa is NAN THANKS FOR YOUR TIME

Re: problems passing info between classes

Posted by Liam Staskawicz at August 09. 2008
Just to make sure, are you properly creating a new instance of your Make class before trying to access its alfNum property? Also, I'm not super ActionScript programmer guy but I've seen class properties in AS3 implemented with the get and set keywords, allowing you to define methods that get called when the property is read and written. Accessing the property through a method may give you better results.

Re: problems passing info between classes

Posted by Forrest Maready at August 31. 2008

Hey Cara-

I'm new here, but am looking forward to some cool projects with Flash and the Make board. Did you ever get your problem resolved? I'm a somewhat newbie coder but might can help. Your code, as Liam mentioned, didn't contain any Make instances, so I would assume creating a "lollipop:Make = new Make();" line would resolve the problem.  A class file doesn't actually create anything, it just makes a blueprint for when you do.

Change your main code to:


public function mainClass(){

lollipop:Make = new Make();  // Here's where you are actually creating an instance of the Make object (called lollipop)

var alfa:Number;
alfa=lollipop.alfNum;  // now you're referencing an actual object- lollipop. Before, with main.alfNum, you weren't referencing anything, as you hadn't actually made any Make objects yet, just the blueprint for one.


trace ("main file says friggin alfa is " + alfa);

_______________________


As I have recently learned OOP, I always use ridiculously obvious variable names so I don't get confused between what's a variable and what's a keyword/function/etc...


Hope this helps.

Re: problems passing info between classes

Posted by Forrest Maready at September 01. 2008
One more thing- don't forget to include your Make.as class at the beginning of main so it will know where to look for the Make blueprint/contsructor, etc.

import Make; // or whatever and wherever the file is in relation to this file
Powered by Ploneboard
Document Actions