q: an idiots guide to learning components?


#1

Hi all,

I’m having quite the problems here, I’m… in over my head :slight_smile:
It’s likely something ridiciously simple, but hey, me, not a programmer… so this be tough stuff to get working :slight_smile: I’ve searched on the web, in these forums, etc., with no luck.

I wish to use a CheckBox component to toggle a layer on and off. Or fade it away, or anything really. … actually I just want to toggle layers on and off, I just figured using the UI components to do so is the “right” way to go about it.

And that should be it… in the end I’m looking to have a couple of checkboxes that can toggle a couple of layers on and off, but here at first it’d just be the one layer I’d be glad to get working.

It’s of course easy enough to drag the CheckBox component onto the stage, but then what? I think I need to declare a function that checks for the status of the CheckBox and does something based on that? Using the Change Handler of the CheckBox to identify which function needs to be invoked.

Where can I go to learn how to declare such a function? Or can anyone explain it?

For what it’s worth I belive I’d like to make one global function that accepts the instance-name of the checkbox as an argument and toggles the appropriate layer. That is, to avoid having like half a dozen functions each hardcoded to toggle a unique layer.

Anyway, an idiots guide to basic useage of Components… anyone know of one? :slight_smile:


#2

I’m new to all this to but wouldnt you want it linked to a url?

If its going to open a layer that would be a diffrant layer right?

Maybe someone who knows will chime in…:shrug:


#3

I’m… not neccessairly following you completly wgreenlee1.

To clarify though, the final effect I’m looking for is that have, say, four images, three with built-in transparencies. The forth solid one goes at the buttom, the others overlayed on top.

I’d then like to have three checkboxes that can toggle each of the transparent layers on and off. Or fade them away for that matter, isn’t important at this time.

I belive it’s a pretty simple process, I just don’t know how to use these UI components. I think I could juryrig something together with symbols and onRease triggers and seperate frames and weird crap… but that doesn’t sound like a very clean solution.

Utilizing a single unified function would be pretty darn useful I think, for this project, and for me generally getting a better hang of Flash.

I just can’t seem to find anything useful on the net that really caters enough to the “Idiot” part of such a Components guide :slight_smile:


#4

The functionality that you are looking for is better handled with a radio button since you only want one selection to be active at any one time. With check boxes, you can have multiple selected at once and is a better choice for a form.


#5

Here,

I made this quick example of one way of doing it. Yes I know, I could have made it easier to update and add more images, but I didn’t have that much time to mess with it.

ImageSelect

Here’s the source file so that you can take it apart: Source


#6

Wow thanks mohh, that’s insanely cool that you’d do that! I do however need checkboxes as I plan to have half a dozen overlays with their own details, and people will be able to check the layers on and off to display the amount of information they want access to.

If you can give some tips on how to change it to checkboxes that’d be pretty damn cool. I’ve learnt a lot from your script as it is though, the solution I’m currently fighting with will definitely end up using interfaces generated at run-time.

I also managed to learn enough of the syntax to get… uh… something going :slight_smile: At the moment I’m having trouble getting an if/then loop working based on if the checkbox is true or false. Bah :slight_smile:

Anyway, thanks a lot for your help, though I could likely still use a little more heh.


#7

To elaborate on my problem…
I don’t know if there’s reason I shouldn’t do it, but I’ve gone with a function that’s called by each CheckBox’s Change Handler.

Thus I’ve defined an “onChange” function that accepts the component name as an argument.

function onChange(component)

I then try and determine if the checkbox is on or off. The idea is that if it’s on (true) then one thing happens, if it’s off (false) another thing:

if (component.getValue)
    {
        trace("IF " + component.getValue());
    }
else
    {
        trace("ELSE " + component.getValue());
    }
}

The intended result was that the output window should read “IF TRUE” when the checkbox was true, otherwise “ELSE FALSE”. That does not happen, the actual result from pressing the checkbox twice is:

IF true
IF false

Which seems to indicate that it always thinks the checkbox is true when it evaluates wether to go with the ‘if’, or the ‘else’ part… it reads it correctly when actually printing true or false in the trace-lines though…

And (obviously-ish) if I force the loop to to always be false it writes ELSE TRUE, ELSE FALSE.

Hm… I hope that makes sense…

Anyway, it seems to me that the problem lies in me relying on

if (component.getValue)

to test for TRUE or FALSE. And… well… that’s where I’m currently stuck. If you, or anyone really, has any insight to what I can do here, that’d be just great.

For what it’s worth I’m sufficiently inexperienced in programming that I’m not even sure I’m going about this the right way, maybe I need to rethink the entire system?


#8

Doh, I just now tried evaluating with

if (component.getValue(true))

and, uh, it seems to be working nicely. I… did not know it needed that syntax.

I hate programming :slight_smile:

Onwards I go!, I may be able to solve this on my own yet! :smiley: Sorry for all the ranting.


#9

More component-fun…

I’ve searched around without any luck, so I turn here once again :slight_smile: This time it seems I’m messing up my data-types. I… have no idea how to go about solving this atm:

Let’s say I currently have variable “selected” holding the string “image1”.
And a symbol on the stage with the instance-name “image1”.

If I make the actionscript “trace(image1._visible)” it outputs “True” or “False”. But if I make the actionscript “trace(selected._visible” it outputs “Undefined”. Despite the variable having the same name as the movieclip

I suspect this is because the variable is a string, not an… object-type?

Some quick fake code to sum up the problem:

//assume a movie-clip object is present with instance-name "image1"

select = "image1";

trace(select._visible);
trace(image1._visible);

// 1st trace outputs Undefined, 2nd outputs True

#10

Ahh,

Now I see what you were after. It shouldn’t be that much more difficult to modify, but if you are planing to make your site “modular” and customizable by your users, a different approach would be better to what I have done. (meaning=more time and planning)

As far as the trace goes, I think that your problem is that you are specifying that select is equal to the string image1. Remove the quotes from image1 and it should work just fine.

//assume a movie-clip object is present with instance-name "image1"

select = image1;

trace(select._visible);
trace(image1._visible);

// they should both output the same results

#11

Thanks mohh, with your help, and a friends help, I’ve managed to stumble my way through the weirdness that is ActionScripting :slight_smile:

The result of it all can be viewed here for what it’s worth.

It’s functional as of now, but not neccessairly finished… still, it works just as I had originally hoped, so that’s nice.

Thanks a lot for your help mohh, even though the code I’m using is currently from-scratch stuff, I’ve still learnt a lot from your example. I’m keeping it around 'till when I can pull myself together and generate the interface at runtime for instance… I thought that was a pretty cool trick (it might be the default way of doing things or whatnot, I’ve just never personally seen it done like that :))

Anyway, thanks :thumbsup:


#12

Hey Gaggle,

That looks great!! What a great way of displaying your level. I’m glad that I was able to help, if any.


#13

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.