Zurück   Flashforum > Flash > ActionScript > ActionScript 1

Antwort
 
LinkBack Themen-Optionen Ansicht
Alt 14-05-2006, 13:22   #1 (permalink)
KD*
derkzer
 
Registriert seit: Jan 2004
Beiträge: 30
Random-Werte zuweisen | laco-tween

Hallo Ihr,

bin gerade etwas am verzweifeln.

Ich tweene mehrere mc's mit den laco-tweens und möchte mittels random zufällige X&Y-Werte zuweisen (die auf jedenfall über 1000 liegen sollen (als bsp)). In der Flashhilfe habe ich das gefunden:

PHP-Code:
function randRange(min:Numbermax:Number):Number {
    var 
randomNum:Number Math.floor(Math.random() * (max min 1)) + min;
    return 
randomNum;
}
for (var 
0100i++) {
    var 
n:Number randRange(411)
    
trace(n);

Das ganze habe ich dann einfach übernommen was natürlich nicht zu dem gewünschten Erfolg führte da immer die gleichen Werte für jeden mc rauskamen.

PHP-Code:
#include "lmc_tween.as"
////////////////////////////////////////////////////
var xKo 40;
var 
yKo 40;
var 
animationtype1 'easeOutElastic';
var 
animationtype2 'easeOutSlap';
////////////////////////////////////////////////////
function randRange(min:Numbermax:Numberlaufvariable:Number):Number {
    var 
randomNum:Number Math.floor(Math.random(laufvariable)*(max-min+1))+min;
    return 
randomNum;
}
for (var 
0i<1i++) {
    var 
xwert:Number randRange(-300, -600);
    var 
ywert:Number randRange(-300, -600);
    
trace(xwert);
    
trace(ywert);
}
////////////////////////////////////////////////////
this.onEnterFrame = function() {
    
t_bg1.tween('_y'yKo1animationtype22);
    
t_bg1.tween('_x'xKo+2601animationtype22);
    
t_bg1.tween('_width'2100.5animationtype20);
    
t_bg1.tween('_height'250animationtype22);
    
t_bg2.tween('_y'yKo+251animationtype22);
    
t_bg2.tween('_x'xKo1animationtype22);
    
t_bg2.tween('_width'5270.5animationtype20);
    
t_bg2.tween('_height'250animationtype22);
    
t_bg3.tween('_y'yKo+501animationtype22);
    
t_bg3.tween('_x'xKo1animationtype22);
    
t_bg3.tween('_width'5520.5animationtype20);
    
t_bg3.tween('_height'25.250animationtype22);
    
t_bg4.tween('_y'yKo+751animationtype22);
    
t_bg4.tween('_x'xKo1animationtype22);
    
t_bg4.tween('_width'5370.5animationtype20);
    
t_bg4.tween('_height'250animationtype22);
    
t_bg5.tween('_y'yKo+1001animationtype22);
    
t_bg5.tween('_x'xKo1animationtype22);
    
t_bg5.tween('_width'5520.5animationtype20);
    
t_bg5.tween('_height'250animationtype22);
    
t_bg6.tween('_y'yKo+1251animationtype22);
    
t_bg6.tween('_x'xKo1animationtype22);
    
t_bg6.tween('_width'5300.5animationtype20);
    
t_bg6.tween('_height'250animationtype22);
    
t_bg7.tween('_y'yKo+1501animationtype22);
    
t_bg7.tween('_x'xKo1animationtype22);
    
t_bg7.tween('_width'5440.5animationtype20);
    
t_bg7.tween('_height'250animationtype22);
    
t_bg8.tween('_y'yKo+1751animationtype22);
    
t_bg8.tween('_x'xKo1animationtype22);
    
t_bg8.tween('_width'4200.5animationtype20);
    
t_bg8.tween('_height'250animationtype22);
    
t_bg9.colorTo(0xFFFFFF1animationtype2);
    
t_bg9.tween('_y'yKo+2151animationtype22);
    
t_bg9.tween('_x'xKo1animationtype22);
    
t_bg9.tween('_width'1550.5animationtype20);
    
t_bg9.tween('_height'250animationtype22);
    
t_bg10.colorTo(0xCCCC001animationtype2);
    
t_bg10.tween('_y'yKo+2151animationtype22);
    
t_bg10.tween('_x'xKo+1701animationtype22);
    
t_bg10.tween('_width'410.5animationtype20);
    
t_bg10.tween('_height'250animationtype22);
    
//////////////////////////////////////////////////////
    
klick1.tween('_y'yKo+2151animationtype13);
    
klick1.tween('_x'xKo+1701animationtype13);
    
delete this.onEnterFrame;
};
////////////////////////////////////////////////////
klick1.onRelease = function() {
    
beweg1();
};
////////////////////////////////////////////////////
function beweg1() {
    
t_bg1.tween('_y'ywert1animationtype22);
    
t_bg1.tween('_x'xwert1animationtype22);
    
t_bg1.tween('_width'10.5animationtype20);
    
t_bg1.tween('_height'250animationtype22);
    
t_bg2.tween('_y'ywert1animationtype22);
    
t_bg2.tween('_x'xwert1animationtype22);
    
t_bg2.tween('_width'10.5animationtype20);
    
t_bg2.tween('_height'250animationtype22);
    
t_bg3.tween('_y'ywert1animationtype22);
    
t_bg3.tween('_x'xwert1animationtype22);
    
t_bg3.tween('_width'10.5animationtype20);
    
t_bg3.tween('_height'250animationtype22);
    
t_bg4.tween('_y'ywert1animationtype22);
    
t_bg4.tween('_x'xwert1animationtype22);
    
t_bg4.tween('_width'10.5animationtype20);
    
t_bg4.tween('_height'250animationtype22);
    
t_bg5.tween('_y'ywert1animationtype22);
    
t_bg5.tween('_x'xwert1animationtype22);
    
t_bg5.tween('_width'10.5animationtype20);
    
t_bg5.tween('_height'250animationtype22);
    
t_bg6.tween('_y'ywert1animationtype22);
    
t_bg6.tween('_x'xwert1animationtype22);
    
t_bg6.tween('_width'10.5animationtype20);
    
t_bg6.tween('_height'250animationtype22);
    
t_bg7.tween('_y'ywert1animationtype22);
    
t_bg7.tween('_x'xwert1animationtype22);
    
t_bg7.tween('_width'10.5animationtype20);
    
t_bg7.tween('_height'250animationtype22);
    
t_bg8.tween('_y'ywert1animationtype22);
    
t_bg8.tween('_x'xKo1animationtype22);
    
t_bg8.tween('_width'10.5animationtype20);
    
t_bg8.tween('_height'250animationtype22);
    
t_bg9.colorTo(0x0000001animationtype2);
    
t_bg9.tween('_y'ywert1animationtype22);
    
t_bg9.tween('_x'xwert1animationtype22);
    
t_bg9.tween('_width'10.5animationtype20);
    
t_bg9.tween('_height'250animationtype22);
    
t_bg10.colorTo(0x0000001animationtype2);
    
t_bg10.tween('_y'ywert1animationtype22);
    
t_bg10.tween('_x'xwert1animationtype22);
    
t_bg10.tween('_width'10.5animationtype20);
    
t_bg10.tween('_height'250animationtype22);

So nun drehe ich alles hin und her aber komme nicht auf einen Ansatz der zu der Lösung führt wie ich mehrere Werte, mehreren mc's zuweise.

Vll hat von euch jemand einen Ansatz/Idee/was auch immer. Wäre sehr schön.

KD
Angehängte Dateien
Dateityp: rar randomlaco.rar (6,0 KB, 5x aufgerufen)
KD* ist offline   Mit Zitat antworten
Alt 14-05-2006, 13:36   #2 (permalink)
tracer
 
Benutzerbild von andretti
 
Registriert seit: Jun 2004
Beiträge: 4.415
aloha!

was is'n das:
PHP-Code:
function randRange(min:Numbermax:Number):Number {//<---- das letzte ":Number"???? 
__________________
Viola per Sempre
Alle Angaben ohne Gewehr!
trace your open mind in variables !
andretti
ActionScript Dictionary
andretti ist offline   Mit Zitat antworten
Alt 14-05-2006, 13:39   #3 (permalink)
................
 
Benutzerbild von Der Frager
 
Registriert seit: Jun 2004
Beiträge: 15.890
Zitat:
Zitat von andretti
aloha!

was is'n das:
PHP-Code:
function randRange(min:Numbermax:Number):Number {//<---- das letzte ":Number"???? 
Hallo andretti...

Das heißt, dass dir diese Funktion eine Nummer zurückliefern muss. Wenn man das return ausnimmt gibt's eine Fehlermeldung.
__________________

ternärer Konditionaloperator

+++ Bitte keine Privat-Nachrichten bezüglich Flashfragen! +++
Der Frager ist offline   Mit Zitat antworten
Alt 14-05-2006, 13:47   #4 (permalink)
................
 
Benutzerbild von Der Frager
 
Registriert seit: Jun 2004
Beiträge: 15.890
@KD* -> Sowas?
PHP-Code:
function beweg1() {
    for (var 
1x<=10x++) {
        var 
xwert:Number randRange(-300, -600);
        var 
ywert:Number randRange(-300, -600);
        
this["t_bg"+x].tween('_y'ywert1animationtype22);
        
this["t_bg"+x].tween('_x'xwert1animationtype22);
        
this["t_bg"+x].tween('_width'10.5animationtype20);
        
this["t_bg"+x].tween('_height'250animationtype22);
    }

__________________

ternärer Konditionaloperator

+++ Bitte keine Privat-Nachrichten bezüglich Flashfragen! +++
Der Frager ist offline   Mit Zitat antworten
Alt 14-05-2006, 13:48   #5 (permalink)
tracer
 
Benutzerbild von andretti
 
Registriert seit: Jun 2004
Beiträge: 4.415
aha!

merci beaucoups!
__________________
Viola per Sempre
Alle Angaben ohne Gewehr!
trace your open mind in variables !
andretti
ActionScript Dictionary
andretti ist offline   Mit Zitat antworten
Alt 14-05-2006, 13:59   #6 (permalink)
KD*
derkzer
 
Registriert seit: Jan 2004
Beiträge: 30
Zitat:
Zitat von Der Frager
@KD* -> Sowas?
PHP-Code:
function beweg1() {
    for (var 
1x<=10x++) {
        var 
xwert:Number randRange(-300, -600);
        var 
ywert:Number randRange(-300, -600);
        
this["t_bg"+x].tween('_y'ywert1animationtype22);
        
this["t_bg"+x].tween('_x'xwert1animationtype22);
        
this["t_bg"+x].tween('_width'10.5animationtype20);
        
this["t_bg"+x].tween('_height'250animationtype22);
    }

Freude!! Ja sowas habe ich wohl gemeint. Dankeschön!

Um das auch verstanden zu haben:
mit
PHP-Code:
for (var 1x<=10x++) 
werden die mc's 1-10 definiert. Daher gibt es dann
auch für jeden mc einen anderen Wert? Richtig?
KD* ist offline   Mit Zitat antworten
Alt 14-05-2006, 14:10   #7 (permalink)
................
 
Benutzerbild von Der Frager
 
Registriert seit: Jun 2004
Beiträge: 15.890
Ja, richtig. Ist halt eine Schleife und kürzer als es so zu machen:
PHP-Code:
var xwert:Number randRange(-300, -600); 
var 
ywert:Number randRange(-300, -600); 
t_bg1.tween('_y'ywert1animationtype22); 
t_bg1.tween('_x'xwert1animationtype22); 
t_bg1.tween('_width'10.5animationtype20); 
t_bg1.tween('_height'250animationtype22); 
var 
xwert:Number randRange(-300, -600); 
var 
ywert:Number randRange(-300, -600); 
t_bg2.tween('_y'ywert1animationtype22); 
t_bg2.tween('_x'xwert1animationtype22); 
t_bg2.tween('_width'10.5animationtype20); 
t_bg2.tween('_height'250animationtype22); 
var 
xwert:Number randRange(-300, -600); 
var 
ywert:Number randRange(-300, -600); 
t_bg3.tween('_y'ywert1animationtype22); 
t_bg3.tween('_x'xwert1animationtype22); 
t_bg3.tween('_width'10.5animationtype20); 
t_bg3.tween('_height'250animationtype22); 
... 
Also es wird immer ein neur x/yWert errechnet und hiermit:
PHP-Code:
this["t_bg"+x
eben der entsprechende MC angesprochen.
__________________

ternärer Konditionaloperator

+++ Bitte keine Privat-Nachrichten bezüglich Flashfragen! +++
Der Frager ist offline   Mit Zitat antworten
Alt 14-05-2006, 14:16   #8 (permalink)
KD*
derkzer
 
Registriert seit: Jan 2004
Beiträge: 30
Ja, definitiv kürzer... Es artet leicht aus wenn man viele mc's zum tweenen hat, da ist mir die Variante doch sehr willkommen und ich danke dir auch recht herzlich für die Hilfe!!
KD* ist offline   Mit Zitat antworten
Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks sind an
Pingbacks sind an
Refbacks sind an



Alle Zeitangaben in WEZ +1. Es ist jetzt 06:01 Uhr.

Domains, Webhosting & Vserver von Host Europe
Unterstützt das Flashforum!
Adobe User Group


Copyright ©1999 – 2012 Marc Thiele