I posted a problem recently and I think I was asking too much too soon, I apoligise for that one. I want to try again with my problem. Basically I am making an interactive circuit builder in flash mx for 8-10 year olds (does anyone remember crocodile clips?).
it is 400k in size, which was too big for on here.
I am having major problems with my code and I want to try to tackle each problem at a time.
The problem is that I have a set of four components; a motor, bulb, buzzer and switch. When a component is dragged off the list and into the circuit it need to check for power and then function accordingly, i.e. on or off. I have achieved this however i need it so when the component is removed from the circuit it then goes off again.
I do not think I have gone the best way to go about this but if you could be kind enough to see the attachment for what I have done it would really be appreciated.
For reference draggable components are called DragBulb, DragMotor, DragBuzzer and DragSwitch
All batteries add the same amount of power regardless of their size.
The code which (should) turn the component on and off is within the movie clip instance…i.e. the DragBulb MC on the stage has two frames and on each frame is code. The first frame is a graphic of the bulb off and the second frame is a MC of the bulb on, same goes for all the components…I did it this way so I can state the variable 'Component’Power (i.e. BulbPower, MotorPower etc…) to go to different frames depending on the amount of current in the circuit from the varibing amount of batteries…if anyone with more actionscript knowledge (all of you probably) thinks there would be a better way to do this?
Many thanks for your time and help, I appreciate it very much!
at the moment there is only 1 battery socket and 1 component socket, the more batteries the brighter and stronger components are. At the end I need 4 or so sockets so components are duplicated and added to different sockets. I also need it to remove components when new ones are dropped on but I think I should be able to work that out.
Have a look here
I hope this is what you want, else feel free to reply;)
The code has been cleaned up and you can easy alter it (eg BatteryPower/Socket choise)
Scotty, you’re a god in my eyes! I am very grateful for what you have done for me.
I was hoping I could be really cheeky and ask you to look over this code and tell me why it’s not working correctly. I have taken the (very) improved code you made and tried to further it by adding one more component slot. However now many strange things happen.
I don’t know how to ask for help without sounding rude but here goes…I need it to check if there is a component already on the socket before it overwrites it with a new one and returns the existing one. I was thinking the pseudocode would be something like:
on release
check which socket is being dropped onto, if it has been dropped on a socket
check if there is a component in the slot
if there is one then
find out what it is
return it
drop the new component
run the power check to powerup the new component if there is power and a complete circuit (i.e. A switch, the sockets will keep the flow of electricity.)
The only problem is that now I have two component slots, which eventually be four. I need to allow for two identical components to be added…I have looked on flash help & the web (flashkit, actionscript.org) for duplicating movieclips but I dont know how you would do it in this situation where they have to be duplicated but only if they are in the left side and not on the circuit…I have been trying to do this for a few days now. All I end up with is a draggable movie clip which duplicates and drags the original, so you just get movie clips everywhere.
I know I am asking a lot of you and feel I have nothing to offer you in return but your help i recieved this morning was a very big light of hope in my project. if you can point me in the right direction to tutorials or help me it would be wondeful.
Hmm, interesting:)
So in my own words, each component can be duplicate once( max 2 identical components), it can replace another component in the socket, but not its “twin”.
And there must be a full circuit before the the components work.
you are correct on everything apart from the fact that they need to put all the components on to make it work,the blue squares will eventually look like sockets. The components are placed on the sockets. A socket will complete the circuit regardless if there is a component on it, it’s only for 8-10 year olds so it needs to be fairly simple.