|
-
Can I send an object as an argument - custom properties?
Hi there, couple questions - keep in mind I have not used Flash since V4 , however I do have some expertise in JavaScript. So, I want a set of buttons that, when clicked, hold their "pressed" state until you click them once again. I need them to remember what state they are in, and communicate that to my HTML Form.
I was pointed to this example:
http://www.flashkit.com/board/showth...=active+button
(at the very bottom of the thread)
In which on his movie clip he has 2 frames, each with stop() on them. He seems to then call a function on press and pass the number of the button 1, 2 or 3. He then sets it to the down frame. He only has it working for one button at a time.
I need all buttons to be able to be on or off, not just one at a time. Were I to do this in JS, I would probably approach it like so.
For the button:
Code:
on(press){
selectButton(this);
}
Then the function
Code:
function selectButton(oButton)
{
newFrame = (oButton.<currentFrame> == 1) ? 2 : 1 ;
oButton.gotoAndPlay(newFrame);
oButton.status = newFrame; // which will be 1 or 2
}
Questions:
a) Can I send the symbol instance to the function as "this" - send itself as an object?
b) Once my function recieves that object (if it can), how would I reference what I am calling <currentFrame> in the above?
c) Does AS support the ternary operator like the first line in my function?
d) Does AS allow custom properties, like "status" which I set.
Am I on the right path or does AS not work this way? I was told they are close so I am hoping I can do some similar things.
Lastly, how would I then pass the 'status' of each button on form submit?
Thanks a bunch
Tom
-
Uses MX 2004 Pro
 Originally Posted by tdellaringa
Questions:
a) Can I send the symbol instance to the function as "this" - send itself as an object?
b) Once my function recieves that object (if it can), how would I reference what I am calling <currentFrame> in the above?
c) Does AS support the ternary operator like the first line in my function?
d) Does AS allow custom properties, like "status" which I set.
Well I'm not the best one to be answering these questions. I'm just a guy who likes to play around with Flash and haven't had any programming experience otherwise, but since no one has answered your questions yet I'll give them a shot.
- Yes (if I'm understanding you correctly). If you did the following:
Code:
moveThis = function (wc) {
wc._x += 1;
};
box.onEnterFrame = function() {
moveThis(this);
};
The function would understand "wc" to be the "box" mc, and move it 1 pixel each frame call.
- You would reference it's current frame using _currentframe
- I never knew the proper terminology for it, but yes. Flash understands 1 as true and 0 as false
- I'm not entirely sure I know what you're looking for here. I know status is a reserved word used in Flash, so maybe that's what you are looking to use. But if you had oButton.myVar = "hello";, tracing oButton.myVar would output "hello".
I have no idea about the submitting of forms, but maybe this link will help you out.
The following code can be used to change the on/off state of three buttons with the instance names "b1", "b2", "b3" on the stage.
Code:
selectButton = function (wb) {
wb._currentframe == 1 ? wb.gotoAndStop(2) : wb.gotoAndStop(1);
wb.status = wb._currentframe;
trace(wb.status);
};
for (i=1; i<=3; i++) {
var wb:Button = eval("b"+i);
wb.onPress = function() {
selectButton(this);
};
}
...or another way...
Code:
selectButton = function () {
this._currentframe == 1 ? this.gotoAndStop(2) : this.gotoAndStop(1);
this.status = this._currentframe;
trace(this.status);
};
for (i=1; i<=3; i++) {
var wb:Button = eval("b"+i);
wb.onPress = selectButton;
}
-
Great start
hey Quixx, thank you very much This really helps, that is just how I want the button to behave. I will check out the link on the form issue.
One thing I wonder - does it make sense to do the whole form in flash versus parts in HTML and parts in Flash? Or does it not matter?
Tom
-
Whoops, one more question - can you explain this line:
var wb:Button
This kind of looks like a symbol in Ruby. Are you simply saying that the Button you are using is shoved into the var wb? Is Button a keyword (noticing in caps)...
Thanks
-
Uses MX 2004 Pro
 Originally Posted by tdellaringa
var wb:Button
This kind of looks like a symbol in Ruby. Are you simply saying that the Button you are using is shoved into the var wb? Is Button a keyword (noticing in caps)...
In a way, yes. var tells Flash that a new variable is being created and that it will be a path for a Button (which as you guessed, is a keyword in flash). I used "wb" in this case, as an abreviation for which button. You could just as easily use:
...but I've read that it's in good programming practice to define the variable itself and what's it going to be used for, so I've been making it a point to do so lately.
As for the form, I don't really know. I've never had to deal with making a form in Flash, and have only done a very basic one in HTML once before. I always try to keep as much code as possible in once place to make things easier to edit and keep track of. So if it's possible to do so, I personally would make the entire form in Flash. But this isn't to say it would be the easiest or best possible plan. Again, I'm really only a novice when it comes to programming.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|