Copy link to clipboard
Copied
I've made a image loader using this code below, if I want this card clickable when its compile, what I suppose to do? please..
var kartu = new card();
var a:int = 0;
var counter:int = 0;
while (a<11)
{
getImage(kartu.player, counter, a);
a = a + 1;
counter=counter+65;
}
function getImage(name, counter, ac)
{
var url:URLRequest = new URLRequest("dekKartu/" + name + ".png");
var loader:Loader = new Loader();
loader.x = counter;
loader.y = 560;
loader.load(url);
addChild(loader);
You should never nest named functions. Pull the test function out on its own.
YOu could be targeting anything by blindly targeting just " x "... it sounds like it is targeting whatever holds all the cards which would explain why they all move. Try changing the test function to be...
function test(evt:MouseEvent):void
{
MovieClip(evt.currentTarget).x += 5;
}
Copy link to clipboard
Copied
One option is to just add an event listener to the loader....
loader.addEventListener(MouseEvent.CLICK, doSomething);
Copy link to clipboard
Copied
but Ned, if I use that code, then all of cards that loaded will move..
I wish I can make each card clickable so I can do something for each card
Copy link to clipboard
Copied
anyone? please..
Copy link to clipboard
Copied
Why will adding an event listener cause anything to move?
Copy link to clipboard
Copied
hahaha sorry I forgot..
I tested "doSomething" with move function, like x = 5. when I run and I click, all of items on screen move, and I can click anywhere..
let me show you, lets say this boxes as cards.
before :
[] [] [] [] [] [] [] [] [] [] []
hello world
after run :
[] [] [] [] [] [] [] [] [] [] []
hello world
how if I just want make 1 card clickable..
like card game, click 1 card to throw 1 card, click deck to get 1 card to hand
Copy link to clipboard
Copied
I don't see how any of the code you have shown will move anything, and adding the event listener I indicated will not either. Show the full code for the doSomething function you wrote. If written properly it should only affect things relative to the button clicked.
Copy link to clipboard
Copied
I sent you the source to message
Copy link to clipboard
Copied
Please keep all information in your posting
Copy link to clipboard
Copied
// I put this on frame
var kartu = new card();
var a:int = 0;
var counter:int = 325;
while (a<11)
{
getImage(kartu.player, counter, a);
a = a + 1;
counter=counter+65;
}
function getImage(name, counter, ac)
{
var url:URLRequest = new URLRequest("dekKartu/" + name + ".png");
var loader:Loader = new Loader();
loader.x = counter;
loader.y = 560;
loader.load(url);
addChild(loader);
}
and I use this on .as file
import flash.events.*;
import flash.net.URLRequest;
import flash.display.Loader;
public class card {
var cardArr:Array = ["A1","A2","A3","B1","B2","B3","C1","C2","C3","D1","D2","D3","E1","E2 ","E3","F1","F2","F3","G1","G2","G3","H1","H2","H3","I1","I2","I3","I4 ","I5","I6",
"A1","A2","A3","B1","B2","B3","C1","C2","C3","D1","D2","D3","E1","E2" ,"E3","F1","F2","F3","G1","G2","G3","H1","H2","H3","I1","I2","I3","I4" ,"I5","I6",
"A1","A2","A3","B1","B2","B3","C1","C2","C3","D1","D2","D3","E1","E2" ,"E3","F1","F2","F3","G1","G2","G3","H1","H2","H3","I1","I2","I3","I4" ,"I5","I6",
"A1","A2","A3","B1","B2","B3","C1","C2","C3","D1","D2","D3","E1","E2" ,"E3","F1","F2","F3","G1","G2","G3","H1","H2","H3","I1","I2","I3","I4" ,"I5","I6",
"A1","A2","A3","B1","B2","B3","C1","C2","C3","D1","D2","D3","E1","E2" ,"E3","F1","F2","F3","G1","G2","G3","H1","H2","H3","I1","I2","I3","I4" ,"I5","I6",
"A1","A2","A3","B1","B2","B3","C1","C2","C3","D1","D2","D3","E1","E2" ,"E3","F1","F2","F3","G1","G2","G3","H1","H2","H3","I1","I2","I3","I4" ,"I5","I6"]
public var player:Array = new Array(11);
public var com1:Array = new Array(11);
public var com2:Array = new Array(11);
public var com3:Array = new Array(11);
public var deck:Array = new Array(136);
public function card() {
var koa_card:Array = generate_deck();
var a:int = 0;
var index_counter:int = 0;
while(a < 180) {
if(a < 11) {
player[index_counter] = koa_card;
}
if(a >= 11 && a < 22) {
com1[index_counter] = koa_card;
}
if(a >= 22 && a < 33) {
com2[index_counter] = koa_card;
}
if(a >= 33 && a < 44) {
com3[index_counter] = koa_card;
}
if(a >= 44) {
deck[index_counter] = koa_card;
}
a = a + 1;
index_counter = index_counter + 1;
if(index_counter > 10 && a < 45){
index_counter= 0;
}
}
}
function generate_deck() {
var shfArr:Array = new Array(180);
shfArr = kocok(cardArr);
return shfArr;
}
function kocok(array) {
var m = array.length, t, i;
while (m) {
i = Math.floor(Math.random() * m--);
t = array
array
array = t;
}
return array;
}
}
please..
Copy link to clipboard
Copied
I do not see anything relative to the event listener I said to add nor the "doSomething" function you say causes everything to move.
Copy link to clipboard
Copied
var kartu = new card();
var a:int = 0;
var counter:int = 325;
while (a<11)
{
getImage(kartu.player, counter, a);
a = a + 1;
counter=counter+65;
}
function getImage(name, counter, ac)
{
var url:URLRequest = new URLRequest("dekKartu/" + name + ".png");
var loader:Loader = new Loader();
loader.x = counter;
loader.y = 560;
loader.load(url);
addChild(loader);
loader.addEventListener(MouseEvent.CLICK, test);
function test(evt:MouseEvent):void
{
x += 5;
}
}
sorry I forgot I have deleted it, because I just test that "test" function
Copy link to clipboard
Copied
You should never nest named functions. Pull the test function out on its own.
YOu could be targeting anything by blindly targeting just " x "... it sounds like it is targeting whatever holds all the cards which would explain why they all move. Try changing the test function to be...
function test(evt:MouseEvent):void
{
MovieClip(evt.currentTarget).x += 5;
}
Copy link to clipboard
Copied
I see I see..
thanks a lot Ned
Copy link to clipboard
Copied
You're welcome